JSON NSDictionaries and NSArrays from the sophisticated YouTube API

I am making an awesome iPhone app that searches for YouTube videos using the JSON API. However, Google is lazy, they just transformed the ATOM feed into JSON. Everything looks like this:

feed->entry[0]->author[0]->name->$t

This means that getting information from NSArray is difficult, since I need to get the key value of an array object of an object of an array of an object of a key.

To check the correctness of the structure, I can choose two things:

  • Use a huge amount of code for each element that I want to check if JSON is correct.
  • Wrap everything in a @try block.

I would choose the second. The problem is that some time ago I read that this is bad practice. It? And if so, is there a shorter way to validate NSArrays en NSDictionaries? My application can never crash, even if the user removes the processor at run time, so not checking at all is not an option.

Could you help me? Thank.

+3
source share
3 answers

Have you tried the GData API? I use it for my application ( http://itunes.apple.com/us/app/skystop/id392782307?mt=8 ) for Youtube Feed. It basically spills out an XML file for all requests, and you can convert it directly to a plist or NSArray file.

+1

, , API JSON ATOM, ? , , , , , - , Google API.

# 2 - , , try catch , . , catch, , , , , , ... , ( , , ), , , ...

0

JSON? , . Json-framework , .

http://code.google.com/p/json-framework/

0

Source: https://habr.com/ru/post/1778593/


All Articles