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.10. Deserializing JSON into Arrays an...

8.10. Deserializing JSON into Arrays and Dictionaries

Problem

You have JSON data and you want to deserialize it into a dictionary or an array.

Solution

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

Discussion

If you already have serialized your dictionary or array into a JSON object (encapsulated inside an instance of NSData, see Recipe 8.9), you should be able to deserialize them back into a dictionary or an array, using the JSONObjectWithData:options:error: method of the NSJSONSerialization class. The object that is returned back by this method will either be a dictionary or an array, depending on the data that we pass to it. Here is an example:


  

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