【问题标题】:Relationship fault on RestKit MappingRestKit 映射上的关系错误
【发布时间】:2015-09-16 08:47:30
【问题描述】:

我真的不明白为什么我会出错:/ 有人可以看看吗?

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})"
)

提前感谢您的帮助!

【问题讨论】:

    标签: ios objective-c restkit


    【解决方案1】:

    我打赌这是错误。

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

    特别是 toKeyPath:@"winners" 您的 Winner 模型没有 winners 属性。

    【讨论】:

    • relationshipMappingFromKeyPath 是 WinnerList 属性,toKeyPath 是 json 属性,不是吗?目的,就是把WinnerMapping的所有内容(很多Winner对象)就是WinnerList对象。所以获胜者不需要获胜者属性
    • 你是对的。我注意到一个无法识别的选择器错误“[Winner Winners]”,并认为是这样。我猜你已经解决了这个问题,如果不是赢家映射在我看来是错误的。也许这会导致解析错误。尝试使用与上述winnerListMapping相同的方式使用字典。
    • 是的,我解决了这个问题。但这不是真正的问题;)我真的不明白为什么它不起作用,但我已经改变了这样做的方式,现在它正在起作用。谢谢:)
    猜你喜欢
    • 1970-01-01
    • 2013-08-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-17
    相关资源
    最近更新 更多