vendredi 31 juillet 2015

How to get and load nested JSON values into Tableview Objective c?

Below I have posted my nested JSON response. I want to get all the keys and key values to load into one tableview like below UI. Please help me!

My JSON

response : {

     ANI =  { 
             name = "anisharmu";
             age  = "10";
     };

     ROC =  { 
             name = "rockins";
             age  = "20";   
     };
}

MY UI Tableview

|------------------------|
  ANI anisharmu - 10
|------------------------|

My Code

 NSError *error;
 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) {

            NSLog(@"%@",jsonDictionary[@"response"][obj][@"name"]);

 }

Aucun commentaire:

Enregistrer un commentaire