0

I am stuck in understanding this json. Can anyone help me in parsing. I need the value of key "ItemNo".

I could only do:

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

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

1 Answer 1

1

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

 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);
}
Sign up to request clarification or add additional context in comments.

3 Comments

To get array need to remove last [0] So i have edited for that
Thank you so much @Anbu.Karthik. Can you please remove the structure screenshot from the answer :)
@Assassin - ya sure

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.