I have the following JSON data:
(
3,
{
body = "123";
date = 1333023644;
mid = 12;
"read_state" = 0;
},
{
body = ":)";
date = 1332968570;
mid = 4;
"read_state" = 1;
},
{
body = "1234";
date = 1331844024;
mid = 1;
"read_state" = 1;
}
)
And I want to get an array of body values with this code:
NSArray *array = [dialogsDictionary objectForKey:@"body"];
But I always get this error:
* Terminating app due to uncaught exception ‘NSInvalidArgumentException’, reason: ‘-[__NSArrayM objectForKey:]:
unrecognized selector sent to instance 0x6b65a60’
Consider this JSON string.
This is a valid JSON string. You can check validity using http://jsonlint.com/
Suppose you have your JSON data in variable
jsonDatawhich is of type NSData. Using SBJSON, you can parse your JSON likeAfter this operation all the values for key
bodywould be in result array.If the ‘3’ was array count, you might have included that value in JSON as,
See this tutorial about JSON. You must have read this website to understand JSON
Added by Hot Licks
What you fail to understand is that the original JSON was essentially this:
It was formatted differently because it was an NSLog object dump, not the original JSON source. Perfectly legitimate JSON.