在Restkit中使用Json Response(iPhone)

时间:2022-10-24 15:03:14

I have a Json Response like this.

我有像这样的Json响应。

{
    "ss": 1,
    "tc": 75,
    "pn": "1",
    "users": [
        {
            "id": "123456",
            "ne": "John Smith",
            "el": "example@example.com"
        },
       {
            "id": "3213243",
            "ne": "iPhone Guy",
            "el": "sdads@dsss.com"
        }
]
}

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.

从上面的响应,我想检查成功(ss)是0还是1.如果它是0,我不需要映射用户我想要映射用户。我怎样才能做到这一点。我是否需要映射ss,tc和pn,或者是否可以检查ss值w / o映射。

Any help is appreciated.

任何帮助表示赞赏。

2 个解决方案

#1


1  

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.

字典值包含值和键。从那我可以得到ss的价值。

#2


0  

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

我不知道我是不是错了。如果它有帮助,请看这个:来自iphone / ipad的json webservice

#1


1  

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.

字典值包含值和键。从那我可以得到ss的价值。

#2


0  

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

我不知道我是不是错了。如果它有帮助,请看这个:来自iphone / ipad的json webservice