1
votes

I am trying to parse the following JSON with 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"
}

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

and corresponding implementation is

+ (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;
}

Similarly the object mapping of ImageUrl Class is

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

But I am getting an exception

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

Please help..

1

1 Answers

0
votes

What is the value that the page key path is being evaluated against? Have you tried using a unit test to perform the mapping?