1

我正在尝试使用RESTKIT解析以下 JSON

{
        “0”:{
            “页”: {
                "url": "http://www.zmtcdn.com/menus/307/1.jpg",
                “thumb_url”:“http://www.zmtcdn.com/menus/307/1_thumb.jpg”
                          }
             },
        “1”:{
            “页”: {
                "url": "http://www.zmtcdn.com/menus/307/2.jpg",
                “thumb_url”:“http://www.zmtcdn.com/menus/307/2_thumb.jpg”
                          }
             },
        “menu_url”:“http://www.zomato.com/ncr/restaurants/south-delhi/mathura-road/sagar-ratna-315/menu#tabtop”
}

我所做的与此相对应的课程是:-

@interface ImageCollections : ZomatoObject

@property (nonatomic, strong) NSString* ignore;
@property (nonatomic, strong) NSString* keyTerm;
@property (nonatomic, strong) ImageUrl*  menus;
@property (nonatomic, strong) ImageUrl* photos;

@end

相应的实现是

+ (RKObjectMapping *) getObjectMapping
{
    RKObjectMapping *objectMapping = [RKObjectMapping mappingForClass:[ImageCollections class]];
    [objectMapping mapKeyPath:@"menu_url" toAttribute:@"ignore"];
    objectMapping.forceCollectionMapping = YES;
    [objectMapping mapKeyOfNestedDictionaryToAttribute:@"keyTerm"];
    [objectMapping mapKeyPath:@"(keyTerm).page" toRelationship:@"menus" withMapping:[ImageUrl getObjectMapping]];
    return objectMapping;
}

类似地,ImageUrl 类的对象映射是

+ (RKObjectMapping *) getObjectMapping
{
    RKObjectMapping *objectMapping = [RKObjectMapping mappingForClass:[ImageUrl class]];
    [objectMapping mapKeyPath:@"url" toAttribute:@"url"];
    [objectMapping mapKeyPath:@"thumb_url" toAttribute:@"thumbUrl"];
    return objectMapping;
}

但我遇到了一个例外

*** 由于未捕获的异常“NSUnknownKeyException”而终止应用程序,原因:“[valueForUndefinedKey:]:此类不符合关键页面的关键值编码。”

请帮忙..

4

1 回答 1

0

评估页面键路径的值是什么?您是否尝试过使用单元测试来执行映射?

于 2012-05-18T14:29:51.707 回答