June 2015
Intermediate to advanced
192 pages
4h 8m
English
You can also use the NSJSONSerializer class to serialize NSDictionary or NSArray; simply use the dataWithJSONObject method.
Here's a simple example assuming that data is NSDictionary you want to convert to JSON:
NSError *error; NSData* jsonData = [NSJSONSerialization dataWithJSONObject: data options: NSJSONWritingPrettyPrinted error: &error];
The dataWithJSONObject:options:error method can take NSArray or NSDictionary and returns an NSData blob with the encoded JSON of the collection you passed. If you pass kNilOptions, the JSON will be encoded in a compact manner; for pretty-printed JSON, pass the option NSJSONWritingPrettyPrinted instead.
Apple's documentation for the NSJSONSerialization ...
Read now
Unlock full access