我在解析
JSON结果中的对象数组时遇到问题.
[ { "first_name":"vijay","last_name":"last","creditCardNumber":"178978977779787979","month":"02","year":"2012","address":"Addres2" } { "first_name":"vijay","address":"Addres2" } { "first_name":"vijay","address":"Addres2" } ]
我希望从数组中的所有对象中提取creditCardNumber值.
解决方法
谷歌“JSON框架”.按照(简单)说明进行安装.
然后去:
//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"]]; }