Cannot access a dictionary created with TouchJSON

73 views Asked by At

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

1

There are 1 answers

0
Srikar Appalaraju On BEST ANSWER

In your json string - NSString *jsonString = @"{\"firtname\": \"Matthieu\",\"lastname\": \"Ravey\",\"age\": 22}"; it says firtstring.

Try accessing this dictionary with same keys !

So the change would be -

NSString *firstname = [dictionary objectForKey:@"firtname"];