2

I have this json:

{
    "status": "ok",
    "post": {
        "id": 171,
        "type": "locations",
        "slug": "plaza-404",
        "url": "http://localhost/?locations=plaza-404",
        "status": "publish",
        "title": "Sucursal Plaza 404",
        "title_plain": "Sucursal Plaza 404",
        "content": "",
        "excerpt": "",
        "date": "2014-03-05 19:59:50",
        "modified": "2014-03-07 19:11:43",
        "categories": [],
        "tags": [],
        "author": {
            "id": 1,
            "slug": "arturocalvo",
            "name": "arturocalvo",
            "first_name": "",
            "last_name": "",
            "nickname": "arturocalvo",
            "url": "",
            "description": ""
        },
        "comments": [],
        "attachments": [],
        "comment_count": 0,
        "comment_status": "closed",
        "custom_fields": {
            "id": [
                "1"
            ],
            "location_id": [
                 "1"
            ],
            "calle": [
                "Av. Gomez Morin No.404  Local A3-5"
            ]
}

And i Want to map only the title the custom field called "calle", this is my interface for Location

@interface Location : NSObject

@property (nonatomic, copy) NSString * name;
@property (nonatomic, copy) NSSet * calle;
@end

and this is my code

RKObjectMapping *locationMapping = [RKObjectMapping mappingForClass:[Location class]];
RKObjectMapping *locationCustomMapping = [RKObjectMapping mappingForClass: [LocationCustom class]];

[locationMapping addAttributeMappingsFromDictionary:@{
                                                      @"title": @"name",
                                                      @"calle": @"calle"
                                                      }];


RKResponseDescriptor *locationResponseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:locationMapping method:RKRequestMethodAny pathPattern:nil keyPath:@"post" statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)];

[objectManager addResponseDescriptor:locationResponseDescriptor];


NSURLRequest *request = [NSURLRequest requestWithURL:baseURL];
RKObjectRequestOperation *objectRequestOperation = [[RKObjectRequestOperation alloc]    initWithRequest:request responseDescriptors:@[ locationResponseDescriptor ]];

But for some reason i cant map it, everythime gets a null value, can somebody help me?

1 Answer 1

4

You are missing a level in the JSON that you need to tell RestKit to navigate. Use:

@"custom_fields.calle": @"calle"

in your mapping.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks a LOT!!, i've been struggling with that for about 2 hours, and actually didnt tried that D:, that resolves my problem, thanks again.
No problem, and welcome to stack overflow! Please up vote answers that helped and tick correct answers to your questions :-)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.