0

これは私のサンプルコードがどのように見えるかです:

{
    "name": "Ahmad Mansour",
    "subjects": [
        {
            "parent_subject_name": "Arabic",
            "subject_name": "Shafahi",
            "exams": [
                {
                    "score": "30.00",
                    "exam_name": "Sa3i 1 "
                },
                {
                    "score": "50.00",
                    "exam_name": "sa3i 2"
                },
                {
                    "score": "100.00",
                    "exam_name": "First Semester Exam"
                }
            ]
        },
        {
            "parent_subject_name": "Arabic",
            "subject_name": "Khati",
            "exams": [
                {
                    "score": "50.00",
                    "exam_name": "Sa3i 1 "
                },
                {
                    "score": "60.00",
                    "exam_name": "sa3i 2"
                },
                {
                    "score": "95.00",
                    "exam_name": "First Semester Exam"
                }
            ]
        },

エンティティの場合subject..私のマッピングは問題なく機能します:

RKEntityMapping *subjectEntityMapping = [RKEntityMapping mappingForEntityForName:kSubjectIdentity inManagedObjectStore:model.managedObjectStore];
[subjectEntityMapping addAttributeMappingsFromDictionary:@{ @"subject_name": @"name",
                                                            @"parent_subject_name" :@"parent_name"
                                                          }];

subjectEntityMapping.identificationAttributes = @[ @"name" ];

RKResponseDescriptor *studentResponseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:subjectEntityMapping pathPattern:kGradesPath keyPath:@"subjects" statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)];

[model.objectManager addResponseDescriptor:studentResponseDescriptor];

しかし、私が試験スコアマッピングを行うと..物事が爆発します:

RKEntityMapping *examEntityMapping = [RKEntityMapping mappingForEntityForName:kExamIdentity inManagedObjectStore:model.managedObjectStore];
[examEntityMapping addAttributeMappingsFromDictionary:@{ @"exams.exam_name": @"name" }];

examEntityMapping.identificationAttributes = @[ @"name" ];

RKResponseDescriptor *examResponseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:examEntityMapping pathPattern:kGradesPath keyPath:@"subjects" statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)];

[model.objectManager addResponseDescriptor:examResponseDescriptor];

次のエラーが表示されます。

 E restkit.object_mapping:RKMappingOperation.m:431 Failed transformation of value at keyPath 'exams.exam_name' to representation of type 'NSString': Error Domain=org.restkit.RKValueTransformers.ErrorDomain Code=3002 "Failed transformation of value '(
    "Sa3i 1 ",
    "sa3i 2",
    "First Semester Exam"
)' to NSString: none of the 2 value transformers consulted were successful." UserInfo=0x9a508a0 {detailedErrors=(
    "Error Domain=org.restkit.RKValueTransformers.ErrorDomain Code=3002 \"The given value is not already an instance of 'NSString'\" UserInfo=0x9a50800 {NSLocalizedDescription=The given value is not already an instance of 'NSString'}",
    "Error Domain=org.restkit.RKValueTransformers.ErrorDomain Code=3000 \"Expected an `inputValue` of type `NSNull`, but got a `__NSArrayI`.\" UserInfo=0x9a50830 {NSLocalizedDescription=Expected an `inputValue` of type `NSNull`, but got a `__NSArrayI`.}"

このマッピングも試しましたが、まったく同じエラーが発生します。

[examEntityMapping addAttributeMappingsFromDictionary:@{ @"exam_name": @"name" }];

examEntityMapping.identificationAttributes = @[ @"name" ];

RKResponseDescriptor *examResponseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:examEntityMapping pathPattern:kGradesPath keyPath:@"subjects.exams" statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)];

アイデア?

4

1 に答える 1

2

試験用の応答記述子を持つべきではありません。サブジェクトにネストされたデータであるため、サブジェクト マッピングの関係を使用してマップする必要があります。

マッピングが1つしか対応していないときに2つの配列にマッピングしようとしているため、応答記述子の使用は機能しません。したがって、RestKit が配列を文字列に変換しようとすると、エラーが発生します。

また、試験名はさまざまなインスタンスで繰り返し使用されるため、試験のマッピングでは、一意の ID に複数の属性を指定する必要があります...

于 2013-10-26T14:24:12.100 に答える