O'Reilly logo

JavaScript JSON Cookbook by Ray Rischpater

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Parsing JSON on iOS in Objective-C

Objective-C's class libraries define the NSJSONSerialization class, which can serialize to and from JSON. It converts JSON to NSDictionary objects of values, with the keys, the names of the slots in the JSON, and the values of their JSON. It's available in iOS 5.0 and later.

How to do it…

Here's a simple example:

NSError* error;
NSDictionary* data = [ NSJSONSerialization
  JSONObjectWithData: json
  options: kNilOptions
  error: &error ];

NSString* call = [ data ObjectForKey: @"call" ];

How it works…

The NSJSONSerialization class has a method, JSONObjectWithData:options:error, that takes an NSString, parsing options, and a place to record errors, and performs JSON parsing. It can accept JSON whose top level is an array ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required