I’m initiating a URL connection and my script is returning the following JSON:
(
1,
{
“id” = <-ID Here->;
hash = <-Hash Here->;
},
(
),
(
) )
All the examples I’ve seen so far seem to have “ids” or identifiers before respective arrays/dictionaries. Despite searching around, I couldn’t find a way to parse this. (i.e. I need to get the first boolean value, the id, the hash, and then the arrays as well (which are empty as of now)).
Sorry if I’m missing something– I’m new to parsing JSON in Obj-C.Thanks for the help.
The feature I use is built in with the Cocoa libraries: the NSJSONSerialization class.
It provides methods for parsing JSON into a graph, and encoding a graph into JSON. The rules are similar to plists (i.e. basic types plus arrays and dictionaries).
If you have NSData (which you can easily get from a string), you do like this:
Then, with your data above, objectAtIndex:0 would be an NSNumber that you can call
boolValueon, objectAtIndex:1 will be an NSDictionary that you can callobjectForKey:@"id"(and @”hash”), etc.