iPhone Guy
iPhone Guy

Reputation: 1305

Working with Json Response in Restkit (iPhone)

I have a Json Response like this.

{
    "ss": 1,
    "tc": 75,
    "pn": "1",
    "users": [
        {
            "id": "123456",
            "ne": "John Smith",
            "el": "[email protected]"
        },
       {
            "id": "3213243",
            "ne": "iPhone Guy",
            "el": "[email protected]"
        }
]
}

Code:

[manager loadObjectsAtResourcePath:@"path/to/resources" usingBlock:^(RKObjectLoader* loader) {


        loader.method = RKRequestMethodPOST;
        loader.params = inputDict;

        loader.onDidLoadResponse  = ^(RKResponse *response)
        {

            NSLog(@"Response is %@",response);// here it contains ss value

        };
        loader.onDidLoadObjectsDictionary = ^(NSDictionary *dictionary)
        {
           // NSLog(@"Dictionary is %@",dictionary);

        };
        loader.onDidFailWithError = ^(NSError *error)
        {
            NSLog(@"Restkit Error is %@",error);  
        };
        loader.onDidLoadObjects = ^(NSArray * objects)
        {
           NSLog(@"Object Count is %d",[objects count]);

        };
    }];

From that above response, i would like to check if the success(ss) is 0 or 1. if it is 0, i don't need to map users else i want to map users. how can i do that. Do i need to map ss,tc and pn or is it possible to check ss value w/o mapping.

Any help is appreciated.

Upvotes: 2

Views: 446

Answers (2)

iPhone Guy
iPhone Guy

Reputation: 1305

I found the solution

#import <RestKit/RKJSONParserJSONKit.h>

RKJSONParserJSONKit *parser = [RKJSONParserJSONKit new];
NSDictionary *ditVal = [parser objectFromString:[response bodyAsString] error:nil];

the dictionary value contains value and key. from that i can get the value of ss.

Upvotes: 1

Siakon
Siakon

Reputation: 13

i dont know if i am wrong again. See this if it helps : json webservice from iphone/ipad

Upvotes: 0

Related Questions