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 ...

Get JavaScript JSON Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.