如何使用json为iphone解析对象数组 [英] how to parse array of objects using json for iphone
本文介绍了如何使用json为iphone解析对象数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在解析JSON结果中的对象数组时遇到问题。
I have a problem parsing the array of objects from the JSON result.
[
{
"first_name":"vijay",
"last_name":"last",
"creditCardNumber":"178978977779787979",
"month":"02","year":"2012",
"address":"Addres2"
}
{
"first_name":"vijay",
"last_name":"last",
"creditCardNumber":"178978977779787979",
"month":"02","year":"2012",
"address":"Addres2"
}
{
"first_name":"vijay",
"last_name":"last",
"creditCardNumber":"178978977779787979",
"month":"02","year":"2012",
"address":"Addres2"
}
]
我希望从数组中的所有对象中提取 creditCardNumber
值。
I wish to extract creditCardNumber
value from all objects in the array.
推荐答案
GoogleJSON框架。按照(简单)说明进行安装。
Google "JSON Framework". Follow the (easy) instructions to install it.
然后去:
//let's say there's NSString *jsonString.
NSArray *userData = [jsonString JSONValue];
NSMutableArray *creditCards = [NSMutableArray array];
for (NSDictionary *user in userData) {
[creditCards addObject:[user objectForKey:@"creditCardNumber"]];
}
你将使用NSMutableArray * creditCards充满NSString而放弃底部包含信用卡号的对象。
You'll drop out the bottom of that with NSMutableArray *creditCards full of NSString objects containing the credit card numbers.
这篇关于如何使用json为iphone解析对象数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文