Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint
Share this Page URL
Help

8. Networking, JSON, XML, and Twitter > 8.9. Serializing Arrays and Dictionarie...

8.9. Serializing Arrays and Dictionaries into JSON

Problem

You want to serialize a dictionary or an array into a JSON object that you can transfer over the network or simply save to disk.

Solution

Use the dataWithJSONObject:options:error: method of the NSJSONSerialization class.

Discussion

The dataWithJSONObject:options:error: method of the NSJSONSerialization class can serialize dictionaries and arrays that contain only instances of NSString, NSNumber, NSArray, NSDictionary variables, or NSNull for nil values. As mentioned, the object that you pass to this method should either be an array or a dictionary.

Now let’s go ahead and create a simple dictionary with a few keys and values:


  

You are currently reading a PREVIEW of this book.

                                                                                        

Get instant access to over
$1 million worth of books and videos.

  

Start a Free Trial