I have to read some values from nested JSON and I can't read them properly. JSON looks like this:
"addons" : [
{
"group_title" : "Veggie Toppings",
"group_type" : "T",
"item_id" : "29",
"addon" : [
{
"id" : "31",
"item_title" : "Ham"
},
{
"id" : "32",
"item_title" : "Mushrooms"
}
]
},
{
"group_title" : "Meat Toppings",
"group_type" : "T",
"item_id" : "33",
"addon" : [
{
"id" : "30",
"item_title" : "Sausage"
}
]
}
And my code is:
-(void)setData:(NSMutableDictionary *)menuItems{
self.menuItem = menuItems;
// [GSDVActivityIndicator stopWithID:kNotificationHello];
self.dictionaryOrder = [NSMutableDictionary dictionaryWithDictionary:[self.menuItem valueForKey:@"order"]];
self.arrayPrices = [NSArray arrayWithArray:[self.menuItem valueForKey:@"price"]];
self.arrayAddons = [NSArray arrayWithArray:[self.menuItem valueForKey:@"addons"]];
self.myAddons = [NSArray arrayWithArray:[self.arrayAddons valueForKey:@"addon"]];
[self setViewGUIData];
NSLog ( @"addons= %@", [self.arrayAddons valueForKey:@"Group_title]);
NSLog ( @"addon = %@", [self.myAddons valueForKey:@"item_title"]);
}
And the result is:
2014-03-24 19:48:04.446 [3698:70b] addons= (
"Veggie Toppings",
"Meat Toppings"
)
2014-03-24 19:48:04.447 [3698:70b] addon = (
(
Ham,
Mushrooms
),
(
"Sausage"
)
)
SO problem is in the second part where the items "ham, mushrooms and sausage" are in bad format and i can't read them and put them in label. Obviously this line is bad :
self.myAddons = [NSArray arrayWithArray:[self.arrayAddons valueForKey:@"addon"]];
But i don't know how to correct it.
Thanks.