I am trying to get some keys and values from below nested JSON response. Below I have mentioned my JSON
response structure, I need to get the all keys(Red, Green)
and key values(Color and ID)
from the below response and load into the Array for tableview cell value.
FYI: I have tried by using NSDictionary
but I am getting all the time unordered values. I need to get ordered values also. Please help me!
{
response: {
RED: {
Color: "red",
color_id: "01",
},
GREEN: {
Color: "green",
color_id: "02",
}
},
Colorcode: { },
totalcolor: "122"
}
My Code:
NSError *error;
NSDictionary *jsonDictionary = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&error];
NSArray *responsData = [jsonDictionary objectForKey:@"response"];
NSLog("%@",[responsData objectAtIndex:0]); // here I am getting bad exception
NSDictionary *d1 = responsData.firstObject;
NSEnumerator *enum1 = d1.keyEnumerator;
NSArray *firstObject = [enum1 allObjects];
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…