Restkit属性映射失败转换错误

这是我的示例代码如下所示:

{ "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)]; 

想法?

您不应该有考试的回复描述符。 它嵌套在主题中的数据,所以它应该使用主题映射关系映射。

使用响应描述符不起作用,因为当映射仅适用于一个时,您试图映射到2个数组。 因此,当RestKit尝试将数组转换为string时,会出现错误。

而且,对于考试映射,您应该为唯一标识指定多个属性,因为考试名称会针对不同的实例重复使用。