Search code examples
jsoncocoa-touchios6

Cocoa touch - Error getting JSON key


So I am parsing the www.twitch.tv API json page.

Here is the link: (these 2 people are normally always streaming - if the json data shows as [] it means they are offline. if someone is offline, json has no data) http://api.justin.tv/api/stream/list.json?channel=vokemodels http://api.justin.tv/api/stream/list.json?channel=mathmind

My problem is that in my iOS application, I can do:

[dictionary objectForKey:@"stream_count"]];

And I do successfully get data from the JSON and it will log correctly. However, when trying to get data from the "screen_cap_url_medium" key, I do the following code:

[dictionary objectForKey:@"screen_cap_url_medium"]];

And I get a (null) when logging. I am absolutely positive I am retrieving the JSON data, and I do not have any typos.

When I NSLog the entire JSON array from one of the above links, the "screen_cap_url_medium" is one of the only keys that are in quotes.

Can anyone tell me what I'm doing wrong?


Solution

  • If you inspect your json you'll see that screen_cap_url_medium is under channel object, so you can access it like this:

    [dictionary valueForKeyPath:@"channel.screen_cap_url_medium"];
    

    PS. Here dictionary is obviously the first object of the root array you get back from your response.