[英]Nested JSON parsing in iOS
I am stuck in understanding this json. 我被困在理解这个json。 Can anyone help me in parsing. 谁能帮我解析。 I need the value of key "ItemNo". 我需要键“ ItemNo”的值。
I could only do: 我只能做:
NSDictionary *json = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
NSArray *arr = [[[json objectForKey:@"ShoppingBagRefList"] objectForKey:@"ShoppingBagRef"] objectAtIndex:0];
if you want to access the single string use the following 如果要访问单个字符串,请使用以下命令
NSString *ItemNo = json[@"ShoppingBagRefList"][@"ShoppingBagRef"][0][@"BagDetail"][@"ShoppingBag"][@"ShoppingBagSectionList"][@"ShoppingBagSection"][0][@"ShoppingBagItemList"][@"ShoppingBagItem"][0][@"ItemNo"];
NSLog(@"ItemNo == %@",ItemNo);
or alternateway 或替代
if you want to access the all string based on ItemNO then use the following 如果要访问基于ItemNO的所有字符串,请使用以下命令
NSArray *ItemNo = json[@"ShoppingBagRefList"][@"ShoppingBagRef"][0][@"BagDetail"][@"ShoppingBag"][@"ShoppingBagSectionList"][@"ShoppingBagSection"][0][@"ShoppingBagItemList"][@"ShoppingBagItem"];
for (NSDictionary *temp in ItemNo) {
NSString *getItemNo = temp[@"ItemNo"];
NSLog(@"ItemNo == %@",getItemNo);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.