How to load jsonDictionary[@"response"][obj][@"color"]
into table view array. Here below sample code I am using but every time I am getting bad exception at return [tableviewArray count];
. Please give some solution for my problem.
NSError *error;
NSDictionary *jsonDictionary = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&error];
// get keys from response dictionary
NSMutableArray * key = [[NSMutableArray alloc] initWithArray:[jsonDictionary[@"response"] allKeys]];
// sort as asending order
NSSortDescriptor* sortOrder = [NSSortDescriptor sortDescriptorWithKey: @"self" ascending: YES];
key = (NSMutableArray *)[key sortedArrayUsingDescriptors: [NSArray arrayWithObject: sortOrder]];
// access inner data from dictonary
for (NSString * obj in key) {
// Here below values I want to apply for tableview array
NSLog(@"%@",jsonDictionary[@"response"][obj][@"color"]);
NSArray *tableviewArray = [jsonDictionary[@"response"][obj][@"color"]];
}
I am getting bad exception on below tableview method
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [tableviewArray count]; // Here am getting bad exception
}
My JSON:
{
response: {
RED: {
Color: "red",
color_id: "01"},
GREEN: {
Color: "green",
color_id: "02"}
},
Colorcode: {},
totalcolor: "122"
}