2015-09-16 32 views
0

我真的不明白爲什麼我有一個錯誤:/ 有人可以看看它嗎?RestKit映射關係錯誤

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]; 

數據模型:

enter image description here

最後:

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

我打賭這是錯誤。

//Link Winner to WinnerList 
[winnerListMapping addPropertyMapping: 
    [RKRelationshipMapping relationshipMappingFromKeyPath:@"winners" 
               toKeyPath:@"winners" 
               withMapping:winnerMapping]]; 

具體的toKeyPath:@"winners"你的贏家模型沒有winners屬性。

+0

relationshipMappingFromKeyPath是一個WinnerList屬性,toKeyPath是一個json屬性,不是嗎?其目的是將WinnerMapping的所有內容(許多Winner對象)都是WinnerList對象。所以贏家不需要贏家屬性 – StrawHara

+0

你是對的。我注意到一個無法識別的選擇器錯誤「[贏家贏家]」,並認爲是這樣。我猜你已經解決了這個問題,如果不是贏家映射對我來說看起來不對。也許這是導致解析錯誤。嘗試使用與上述winnerListMapping相同的字典。 –

+0

是的,我解決了這個問題。但這不是真正的問題;)我真的不明白爲什麼它不工作,但我改變了我的方式來做到這一點,現在它的工作。謝謝 :) – StrawHara