0

I'm new in iPhone programming. I have to parse this data in JSON in Objective-C.

{"success":1,"check":[{"ChkKey":"2","ChkDeb":"Connection 1","ChkSSID":"Netgear-1111","ChkIP":"192.168.2.103","ChkBlk":"0"}]}

I follow the example for parsing data with Json. But this JSON is so different. It is composed by two Array. How can i proceed? Thanks - A.b.

1

1 Answer 1

3

How about trying something like this ...

//JSON string
NSString *jsonString = @"{\"success\":1,\"check\":[{\"ChkKey\":\"2\",\"ChkDeb\":\"Connection 1\",\"ChkSSID\":\"Netgear-1111\",\"ChkIP\":\"192.168.2.103\",\"ChkBlk\":\"0\"}]}";

//Parse JSON string into an NSDictionary
NSError *e = [[NSError alloc] init];
NSDictionary *jsonData = [NSJSONSerialization JSONObjectWithData:[jsonString dataUsingEncoding:NSUTF8StringEncoding] options:NSJSONReadingMutableContainers error:&e];

//Output the value of success
NSLog(@"Success:%@", [jsonData objectForKey:@"success"]);

//Get data in the check array
NSDictionary *checkData = [[jsonData objectForKey:@"check"] objectAtIndex:0];

//Output the value of ChkSSID
NSLog(@"ChkSSID:%@", [checkData objectForKey:@"ChkSSID"]);
2
  • Thank you so much Darren. In this way I retain what I need. Nov 3, 2012 at 23:45
  • No problem at all! I am glad it helped. Nov 4, 2012 at 17:29

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.