Posted by: bearc0025 | March 20, 2009

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

Advertisements

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

Categories

%d bloggers like this: