How to do JSON Parsing in IOS

If you don’t know what JSON is, it’s a simple human readable format that is often used to send data over a network connection.

For example, if you have an array of three strings, the JSON representation would simply be:
[“test1”, “test2”, “test3”]

If you have a Pet object with member variables name, breed, and age, the JSON representation would simply be:
{“name” : “Dusty”, “breed”: “Poodle”, “age”: 7}

The reason JSON is important is that many third parties such as Google, Yahoo, or Kiva make web services that return JSON formatted data when you visit a URL with a specified query string. If you write your own web service, you’ll also probably find it really easy to convert your data to JSON when sending to another party.

If you’ve had to parse JSON in your iOS apps in the past, you’ve probably used a third party library such as JSON Framework.
Well with iOS 5, needing to use a third party library for JSON parsing is a thing of the past. Apple has finally added a JSON library in Cocoa and I must say I personally like it very much!

You can turn objects like NSString, NSNumber, NSArray and NSDictionary into JSON data and vice versa super easily. And of course no need to include external libraries – everything is done natively and super fast.