Skip to content

JSON on iPhone

For JSON on the iPhone, I recommend this http://code.google.com/p/json-framework/

For “installation“…

Option 1: Copy the JSON source files into your project

This is the simplest option and should always work—regardless of whether you’re creating an application for the iPhone or a desktop Mac.

1. Drag the JSON folder from the distribution and drop it on the ‘Classes’ group in the ‘Groups & Files’ menu of your Xcode project.
2. Tick the ‘Copy items into destination group’s folder’ option.
3. Use #import “JSON.h” in your source files.

It adds the methods to NSString and NSObject so you can use NSString to call…

NSArray *items = [jsonResp JSONValue];

Depending on  the JSON string it returns an NSArray or NSDictionary. If your JSON has multiple items, it returns an array of NSDictionary containing the elements.

Calling JSONRepresentation on an NSObject returns it’s JSON string representation. This is only good for NSArray and NSDictionary.

NSString *json = [items JSONRepresentation];

This uses your class members/properties to develop the JSON string.

Boom. Done. You can see other available methods and such at http://code.brautaset.org/JSON/index.html