簡體   English   中英

iOS中的嵌套JSON解析

[英]Nested JSON parsing in iOS

我被困在理解這個json。 誰能幫我解析。 我需要鍵“ ItemNo”的值。

我只能做:

NSDictionary *json = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];

NSArray *arr = [[[json objectForKey:@"ShoppingBagRefList"] objectForKey:@"ShoppingBagRef"] objectAtIndex:0];

如果要訪問單個字符串,請使用以下命令

NSString *ItemNo = json[@"ShoppingBagRefList"][@"ShoppingBagRef"][0][@"BagDetail"][@"ShoppingBag"][@"ShoppingBagSectionList"][@"ShoppingBagSection"][0][@"ShoppingBagItemList"][@"ShoppingBagItem"][0][@"ItemNo"];

NSLog(@"ItemNo == %@",ItemNo);

或替代

如果要訪問基於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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM