How to parse a JSON URL in iOS and Cocoa

Both Cocoa and iOS have built-in methods to parse (and generate) JSON data using NSJSONSerialization.

Most commonly you’ll want to call a URL with parameters which will return some data. You take this output and tell Objective-C that it’s JSON, then typecast the return to an array or a dictionary which in turn lets you access the data. It’s genius!

Here’s an example:

This content is for members only.

Once you have access to the top level elements you can then loop through each one, examining what’s in it and access what you need.

Further Reading

Leave a Reply