0

我是 iPhone 编程的新手。我必须在 Objective-C 中以 JSON 格式解析这些数据。

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

我按照使用 Json 解析数据的示例进行操作。但是这个 JSON 是如此不同。它由两个Array组成。我该如何进行?谢谢 - 抗体

4

1 回答 1

3

试试这样的东西怎么样...

//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"]);
于 2012-10-27T00:14:12.377 回答