I’ve written previously on how to serialize Objective-C objects to JSON as part of a simple Flickr photo viewer. At the time, Apple did not have support for JSON directly within the frameworks, therefore my examples used an open source JSON library. However, since iOS 5 app developers have had the opportunity to use the NSJSONSerialization class to convert objects to JSON and vice versa.
This tutorial will show you how to convert several objects into JSON. With most of my code examples I like to keep things pretty simple, so you can walk away with some working code as a starting point for your own work. This tip is no exception: I’ll create a dictionary object that contains several key/value pairs. I’ll also add an array of objects to the dictionary. I’ll use NSJSONSerialization object to serialize the dictionary into JSON.