我真的不明白我为什么会有错误:/ 有人可以看一下吗?
Json文件:
{
"total_count": 3,
"incomplete_results": false,
"winners": [
{
"windate": "2015-05-26 17:11:30.0",
"gift": "foo",
"email": "foo",
"giftack": "foo",
"lastname": "foo",
"gender": "foo",
"firstname": "foo",
"updategiftdate":null
}
],
"nbWinners": 3
}
映射文件:
//Winner List Mapping
RKEntityMapping *winnerListMapping =
[RKEntityMapping mappingForEntityForName:@"WinnerList"
inManagedObjectStore:managedObjectStore];
winnerListMapping.identificationAttributes = @[@"nbWinners"];
[winnerListMapping addAttributeMappingsFromDictionary:@{
@"total_count" : @"totalCount",
@"incomplete_results" : @"incompleteResults",
@"nbWinners" : @"nbWinners" }];
//Winner Mapping
RKEntityMapping *winnerMapping =
[RKEntityMapping mappingForEntityForName:@"Winner"
inManagedObjectStore:managedObjectStore];
winnerMapping.identificationAttributes = @[@"winDate"];
[winnerMapping addAttributeMappingsFromArray:@[
@"windate", @"gift", @"email", @"giftack", @"lastname", @"gender", @"firstname", @"updategiftdate"]];
//Link Winner to WinnerList
[winnerListMapping addPropertyMapping:
[RKRelationshipMapping relationshipMappingFromKeyPath:@"winners"
toKeyPath:@"winners"
withMapping:winnerMapping]];
//Run Mapping
RKResponseDescriptor *winnerListResponseDescriptor =
[RKResponseDescriptor responseDescriptorWithMapping:winnerListMapping
method:RKRequestMethodGET
pathPattern:@"example.json"
keyPath:nil
statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)
];
[objectManager addResponseDescriptor:winnerListResponseDescriptor];
数据模型:
最后:
2015-09-16 10:13:25.018 iDol Check[26031:954937]
(
"<WinnerList: 0x7f9d0167f4b0> (entity: WinnerList; id: 0xd0000000000c0000 <x-coredata://7E40E0FD-3677-45EA-9BD1-59F755C05BC5/WinnerList/p3> ; data: {\n incompleteResults = 0;\n nbWinners = 3;\n totalCount = 3;\n winners = \"<relationship fault: 0x7f9d0167afa0 'winners'>\";\n})"
)
提前感谢您的帮助!
答案 0 :(得分:0)
我认为这是错误。
//Link Winner to WinnerList
[winnerListMapping addPropertyMapping:
[RKRelationshipMapping relationshipMappingFromKeyPath:@"winners"
toKeyPath:@"winners"
withMapping:winnerMapping]];
具体而言,您的获胜者模型的toKeyPath:@"winners"
没有winners
属性。