views:

301

answers:

1

Hello!

I have a JSON String which I transform to a NSDictionary, and the I get the values for the key "people" to a NSDictionary:

NSDictionary *testDict = [jsonString JSONValue];
NSDictionary *peopleDict = [testDict objectForKey:@"people"];

A NSLog of peopleDict

NSLog(@"%@", peopleDict);

return me the following:

{
0 =     {
    id = 1;
    name = Doe;
    date = "Fri Dec 04 13:50:30 +0200 2009";
};
1 =     {
    id = 20;
    name = Mr. T;
    date = "Fri Nov 18 17:55:30 +0200 2009";
};
2 =     {
    id = 100;
    name = TestName;
    date = "Mon Nov 30 12:00:10 +0200 2009";
};
}

The number of results, I know (in this case 3). But how could I access the rows 0..2 and the key-values? id is an int value, name a String, and date also a String.

Does anyone know?

Thanks a lot in advance & Best Regards.

+3  A: 
for (id key in peopleDict) {
  NSLog(@"key: %@, value: %@", key, [peopleDict objectForKey:key]);
}

Here's a link to NSDictionary reference

you may want to take a look to: Accessing Keys and Values methods:

  • allKeys
  • allKeysForObject:
  • allValues
  • getObjects:andKeys:
  • objectForKey:
  • objectsForKeys:notFoundMarker:
  • valueForKey:
makevoid