Class

NSJSONSerialization

An object that converts between JSON and the equivalent Foundation objects.

Declaration

@interface NSJSONSerialization : NSObject

Overview

You use the NSJSONSerialization class to convert JSON to Foundation objects and convert Foundation objects to JSON.

A Foundation object that may be converted to JSON must have the following properties:

Other rules may apply. Calling isValidJSONObject: or attempting a conversion are the definitive ways to tell if a given object can be converted to JSON data.

Topics

Creating a JSON Object

+ JSONObjectWithData:options:error:

Returns a Foundation object from given JSON data.

+ JSONObjectWithStream:options:error:

Returns a Foundation object from JSON data in a given stream.

Creating JSON Data

+ dataWithJSONObject:options:error:

Returns JSON data from a Foundation object.

+ writeJSONObject:toStream:options:error:

Writes a given JSON object to a stream.

+ isValidJSONObject:

Returns a Boolean value that indicates whether a given object can be converted to JSON data.

Constants

NSJSONReadingOptions

Options used when creating Foundation objects from JSON data—see JSONObjectWithData:options:error: and JSONObjectWithStream:options:error:.

NSJSONWritingOptions

Options for writing JSON data.

Relationships

Inherits From

See Also

JSON

Using JSON with Custom Types

Demonstrates approaches for encoding and decoding different kinds of JSON in Swift.

Beta Software

This documentation contains preliminary information about an API or technology in development. This information is subject to change, and software implemented according to this documentation should be tested with final operating system software.

Learn more about using Apple's beta software