我很难将 JSON 映射到我的 RestKit 应用程序中。我也想将它保存在核心数据中。因此,这里有两个图像链接。第一张图片,我的 JSON 的样子。
第二张图片是我的核心数据库的样子。
现在首先我制作了没有核心数据层的应用程序。因此,只需读取数据并使用它。那时一切正常。但是对于核心数据,我遇到了一些这样的映射错误。
日志
2013-01-10 10:46:02.663 Offitel2[27978:6813] D restkit.object_mapping:RKMappingOperation.m:635 Did not find mappable relationship value keyPath 'Person'
2013-01-10 10:46:02.664 Offitel2[27978:6813] D restkit.object_mapping:RKMappingOperation.m:635 Did not find mappable relationship value keyPath 'Function'
2013-01-10 10:46:02.664 Offitel2[27978:6813] D restkit.object_mapping:RKMappingOperation.m:635 Did not find mappable relationship value keyPath 'Department'
2013-01-10 10:46:02.665 Offitel2[27978:6813] D restkit.object_mapping:RKMappingOperation.m:635 Did not find mappable relationship value keyPath 'Company'
2013-01-10 10:46:02.672 Offitel2[27978:164f] W restkit.core_data:RKManagedObjectRequestOperation.m:555 Caught undefined key exception for keyPath 'user' in mapping result: This likely indicates an ambiguous keyPath is used across response descriptor or dynamic mappings.
2013-01-10 10:46:02.673 Offitel2[27978:164f] W restkit.core_data:RKManagedObjectRequestOperation.m:555 Caught undefined key exception for keyPath 'function' in mapping result: This likely indicates an ambiguous keyPath is used across response descriptor or dynamic mappings.
2013-01-10 10:46:02.674 Offitel2[27978:164f] W restkit.core_data:RKManagedObjectRequestOperation.m:555 Caught undefined key exception for keyPath 'department' in mapping result: This likely indicates an ambiguous keyPath is used across response descriptor or dynamic mappings.
2013-01-10 10:46:02.676 Offitel2[27978:164f] W restkit.core_data:RKManagedObjectRequestOperation.m:555 Caught undefined key exception for keyPath 'company' in mapping result: This likely indicates an ambiguous keyPath is used across response descriptor or dynamic mappings.
这就是我在代码中进行关系映射的方式。
RKRelationshipMapping* relationUserMapping = [RKRelationshipMapping relationshipMappingFromKeyPath:@"Person"toKeyPath:@"user"withMapping:personMapping];
RKRelationshipMapping* relationFunctionMapping = [RKRelationshipMapping relationshipMappingFromKeyPath:@"Function"toKeyPath:@"function"withMapping:functionMapping];
RKRelationshipMapping* relationDepartmentMapping = [RKRelationshipMapping relationshipMappingFromKeyPath:@"Department"toKeyPath:@"department"withMapping:departmentMapping];
RKRelationshipMapping* relationCompanyMapping = [RKRelationshipMapping relationshipMappingFromKeyPath:@"Company"toKeyPath:@"company"withMapping:companyMapping];
NSLog(@"till here7");
[dataMapping addPropertyMapping:relationUserMapping];
[dataMapping addPropertyMapping:relationFunctionMapping];
[dataMapping addPropertyMapping:relationDepartmentMapping];
[dataMapping addPropertyMapping:relationCompanyMapping];
任何人都可以帮我解决这个问题。我在核心数据的映射上苦苦挣扎了好几天。
亲切的问候