-1

Can anyone tell me how to find the model from this ?

it is giving me null all the time

 {
"Status": 200,
"Data": [
    {
        "id": "1",
        "custno": "0000235",
        "locno": "00001",
        "mfg": "KABA-MAS",
        "model": "Cencon Gen II",
        "serial": "GF8912",
        "install": "2011-10-01",
        "removed": "0000-00-00",
        "warranty": "2012-01-10",
        "seragrno": "A",
        "equiploc": "Testing",
        "notes": "This is a test lock to test our system.  I this is it good.",
        "invoice": "A",
        "eqtype": "Lock",
        "plan": "1",
        "status": "0",
        "image": "cencon_main_1318703242.gif",
        "pmrequired": "1",
        "locktime": null,
        "lockby": null,
        "pmrequiredText": "Yes",
        "statusText": "Active",
        "planTypeText": "Plan I"
    },
    {
        "id": "2",
        "custno": "0000235",
        "locno": "00001",
        "mfg": "adsdad",
        "model": "",
        "serial": "",
        "install": "2011-10-24",
        "removed": "0000-00-00",
        "warranty": "0000-00-00",
        "seragrno": "",
        "equiploc": "",
        "notes": "",
        "invoice": "",
        "eqtype": "",
        "plan": "",
        "status": "-1",
        "image": "",
        "pmrequired": "0",
        "locktime": null,
        "lockby": null,
        "pmrequiredText": "No",
        "statusText": "Pending",
        "planTypeText": null
    }
]

}

Jean-Luc Godard
  • 1,873
  • 3
  • 28
  • 53

4 Answers4

0

I am not sure...but there should be some obj.value type of structure, like in javascript u can access it using something like "responce.data.model"

www.amitpatil.me
  • 3,001
  • 5
  • 43
  • 61
0

assuming the JSON has been turned into an NSDictionary:

NSArray *items = [dictionary objectForKey:@"Data"];
for (item in items) {
    NSLog(@"model = %@", [item objectForKey:@"model"]);
}

If you are looking for how to turn the JSON into an NSDictionary try:

iPhone/iOS JSON parsing tutorial

Community
  • 1
  • 1
XJones
  • 21,959
  • 10
  • 67
  • 82
0

Use SBJsonParser for parsing the response. And "data" field is array of dictionary.

SBJsonParser    *parser     = [[SBJsonParser alloc] init];

// parsing the JSON
NSMutableDictionary *jsonDictionary = [parser objectWithString:response];

NSMutableArray *dataArray = [jsonDictionary objectForKey:@"data"];

So, u can use something like this:-

for(NSMutableDictionary *tempDictionary in dataArray)          
{
    NSLog(@"id is %@",[dataArray objectForKey: @"description"]);
}
Maulik
  • 19,348
  • 14
  • 82
  • 137
Ashwin Kumar
  • 622
  • 4
  • 7
0

try this :

    NSData *responseData;
    NSMutableDictionary *response ;

    NSString *urlStr = [NSString stringWithFormat:@"http://www.example.com"];
    NSLog(@"%@",urlStr);
    NSURLRequest *request = [[NSURLRequest alloc] initWithURL:[NSURL URLWithString:[urlStr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]];

    responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];

    NSString *json = [[[NSString alloc] initWithData:responseData encoding:NSASCIIStringEncoding] autorelease];

    response = (NSMutableDictionary *)[json JSONValue]; 

Then you'll have dictionary response. Now you can access it as

NSLog(@"%@",[response valueForKey:@"Data"] objectAtIndex:yourIndexValue] valueForKey:@"model"]);
Maulik
  • 19,348
  • 14
  • 82
  • 137