如何使用 JSON-Framework 解析 iPhone SDK (XCode) 中的 JSON 对象 [英] How to parsing JSON object in iPhone SDK (XCode) using JSON-Framework
本文介绍了如何使用 JSON-Framework 解析 iPhone SDK (XCode) 中的 JSON 对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这样的 JSON 对象:
I have JSON object like this :
{ "data":
{"array":
["2",
{"array":
[
{"clientId":"1","clientName":"Andy","job":"developer"},
{"clientId":"2","clientName":"Peter","job":"carpenter"}
]
}
]
},
"message":"MSG0001:Success",
"status":"OK"
}
我想使用 JSON 框架获取数组 [0] 值 (2) 和数组 [1] 值(clientId、clientName、job).你知道怎么做吗?
I want to get the array[0] value (2) and array[1] value (clientId, clientName, job) using JSON-Framework. Do you have any idea how to do that?
推荐答案
假设您已遵循 安装 JSON-Framework 到您的项目的说明,这是您如何使用它(取自 此处的文档) :
Assuming you've followed the instructions to install JSON-Framework into your project, here's how you use it (taken from the docs here) :
// Parse the string into JSON
NSDictionary *json = [myString JSONValue];
// Get the objects you want, e.g. output the second item's client id
NSArray *items = [json valueForKeyPath:@"data.array"];
NSLog(@" client Id : %@", [[items objectAtIndex:1] objectForKey:@"clientId"]);
这篇关于如何使用 JSON-Framework 解析 iPhone SDK (XCode) 中的 JSON 对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文