1
我试图用RESTKIT解析嵌套动态JSON与RestKit
{ "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" }
类correponding解析以下JSON到这里面我已经做的是: -
@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;
}
但我得到一个异常
*** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[ valueForUndefinedKey:]: this class is not key value coding-compliant for the key page.'
请帮助..