I have create JSON data through coding so don’t consider it just check the following answer
/// Create dictionary from following code
/// it just for input as like your code
NSMutableDictionary * dict = [[NSMutableDictionary alloc] init];
NSMutableDictionary * innr = [[NSMutableDictionary alloc] init];
[innr setObject:@"red" forKey:@"Color"];
[innr setObject:@"01" forKey:@"color_id"];
NSMutableDictionary * outer = [[NSMutableDictionary alloc] init];
[outer setObject:innr forKey:@"RED"];
innr = [[NSMutableDictionary alloc] init];
[innr setObject:@"green" forKey:@"Color"];
[innr setObject:@"02" forKey:@"color_id"];
[outer setObject:innr forKey:@"GREEN"];
[dict setObject:outer forKey:@"response"];
// ANS ------ as follow
// get keys from response dictionary
NSMutableArray * key = [[NSMutableArray alloc] initWithArray:[dict[@"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) {
NSLog(@"%@",dict[@"response"][obj][@"Color"]);
NSLog(@"%@",dict[@"response"][obj][@"color_id"]);
}
I think you want same and it will help you!
10
solved How to get the values from nested JSON – Objective c