-2

I am trying to get particular datas from below JSON and store into NSMutableArray for loading tableview. Now The problem is I don't know how to get "names and grade values" and want to store into NSMutableArray for tableview listing purpose.

response {

   Private { 

          0 = { 
                  name : nanci,
                  grade : A
              };  
          1 = { 
                  name : nanci,
                  grade : B
              };  
          }
   Public { 

          0 = { 
                  name : doly,
                  grade : A
              };  
          1 = { 
                  name : mali,
                  grade : B
              };  
            }
         }

My Tableview looks below

----------------------------------
     name           grade
----------------------------------
     doly               A
----------------------------------

Please help me how to get values from JSON and store into NSMutableArray.

0

1 Answer 1

-1

Try this way to get data from json response

NSMutableDictionary *yourJsonData = yourjsonresponsedata;
    // get private key data
    for (int i=0; i<[[[yourJsonData objectForKey:@"Private"] allKeys] count]; i++) {
        NSLog(@"name = %@",[[[yourJsonData objectForKey:@"Private"] objectForKey:[NSString stringWithFormat:@"%d",i]] objectForKey:@"name"]);
        NSLog(@"Grade = %@",[[[yourJsonData objectForKey:@"Private"] objectForKey:[NSString stringWithFormat:@"%d",i]] objectForKey:@"grade"]);
    }
Sign up to request clarification or add additional context in comments.

6 Comments

Awesome @Dharmesh...Can I store both values into Single NSMUtableArray and want to get both private and public. Actually into my tableview I will create two section one for private another one for public.
No you store different array because you use two section (private, public) so first section number of row count data first array and another array data for second section. @SteaveJobs
For example If I use search..can I do by both array?
yes if you use two section for table then use two array. @SteaveJobs
And your json formate is complicated please use this json formate so easy way to get data. { "Private" :[ { "name" : "nanci", "grade" : "A" }, { "name" : "nanci", "grade" : "B" } ], "Public" :[ { "name" : "nanci", "grade" : "A" }, { "name" : "nanci", "grade" : "B" } ] } @SteaveJobs
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.