JSON oh JSON

While I do prefer to use JSON, instead of XML. I use to prefer it, but for the wrong reasons. Well, not wrong, but you can always improve right? So why do I love it?

– Lighter than XML

NSDictionary *dictionary = [NSJSONSerialization JSONObjectWithData:myJsonData options:kNilOptions error:&error];

Well the first is really nice, but it doesn’t really help us out, at least directly. The second is just glorious. You get a NSDictionary, that you can use across all your app, with one single line. What’s the catch? In terms of visibility is just wrong. I know I have my data there, but does the next guy that is going to support my app knows that? I can leave some comments…. I promise.. Instead, just create a class to hold that data, and give it some meaning. What I would recomment is something like this:

- (id)initWithDictionaryFromJSON:(NSDictionary*)dictionary;

It is boring, but it gives visibility, helps maintenance,  and gives meaning to your data.

Advertisements
Tagged , , , ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: