gpt4 book ai didi

iphone - 使用 RestKit 解析嵌套的动态 JSON

转载 作者:行者123 更新时间:2023-11-28 17:33:08 25 4
gpt4 key购买 nike

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

{        "0": {            "page": {                "url": "http://www.zmtcdn.com/menus/307/1.jpg",                "thumb_url": "http://www.zmtcdn.com/menus/307/1_thumb.jpg"                          }             },        "1": {            "page": {                "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"}

The class correponding to this which I have made is : -

@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;
}

但是我得到了一个异常(exception)

*** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[ valueForUndefinedKey:]: this class is not key value coding-compliant for the key page.'

请帮忙..

最佳答案

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

关于iphone - 使用 RestKit 解析嵌套的动态 JSON,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10651577/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com