如何使用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-Framework获取array [0] value(2)和array [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屋!
查看全文