Search code examples
ioscocoa-touchtouchjson

How do I get properties out of NSDictionary?


I have a webservice that returns data to my client application in JSON. I am using TouchJson to then deserialize this data into a NSDictionary. Great. The dictionary contains a key, "results" and results contains an NSArray of objects.

These objects look like this when printed to log i.e

NSLog(@"Results Contents: %@",[resultsArray objectAtIndex:0 ]);

Outputs:

Results Contents: {
    creationdate = "2011-06-29 22:03:24";        
    id = 1;
    notes = "This is a test item";
    title = "Test Item";
    "users_id" = 1;
}

I can't determine what type this object is. How do I get the properties and values from this object?

Thanks!


Solution

  • To get the content of a NSDictionary you have to supply the key for the value that you want to retrieve. I.e:

    NSString *notes = [[resultsArray objectAtIndex:0] valueForKey:@"notes"];