I am trying to use TouchJSON and here is what I have done to test it :
NSString *jsonString = @"{\"firtname\": \"Matthieu\",\"lastname\": \"Ravey\",\"age\": 22}";
NSData *jsonData = [jsonString dataUsingEncoding:NSUTF8StringEncoding];
NSError *error = nil;
NSDictionary *dictionary = [[CJSONDeserializer deserializer] deserializeAsDictionary:jsonData error:&error];
NSString *firstname = [dictionary objectForKey:@"firstname"];
NSLog(@"%@", firstname);
But it logs null
instead of Matthieu, what am I missing ?
Thanks
In your json string -
NSString *jsonString = @"{\"firtname\": \"Matthieu\",\"lastname\": \"Ravey\",\"age\": 22}";
it saysfirtstring
.Try accessing this dictionary with same keys !
So the change would be -
NSString *firstname = [dictionary objectForKey:@"firtname"];