【发布时间】:2016-02-16 09:55:44
【问题描述】:
我在尝试解析以下 json 数组时遇到了困难。如何解析它。网络上的其他答案似乎无法解决我的问题。
{
"status": 1,
"value": {
"details": [
{
"shipment_ref_no": "32",
"point_of_contact": {
"empid": ""
},
"products": {
"0": " Pizza"
},"status": "2"
},
{
"shipment_ref_no": "VAPL/EXP/46/14-15",
"point_of_contact": {
"empid": "60162000009888"
},
"products": {
"0": "MAIZE/CORN STARCH"
},
"status": "5"
}
]
}
}
我必须访问每个键的值。
以下是我的代码
NSString* pendingResponse = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
NSData *jsonData = [pendingResponse dataUsingEncoding:NSUTF8StringEncoding];
NSDictionary *jsonDic = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingAllowFragments error:nil];
NSArray *argsArray = [[NSArray alloc] initWithArray:[jsonDic objectForKey:@"details"]];
NSDictionary *argsDict = [[NSDictionary alloc] initWithDictionary:[argsArray objectAtIndex:0]];
NSLog(@"keys = %@", jsonDic[@"values"]);
【问题讨论】:
-
展示你编写的代码
-
为什么不使用第三方库/pod 来帮助您进行解析?
-
尝试用我提供的代码替换您的代码。
标签: ios objective-c json