An object that converts between JSON and the equivalent Foundation objects.
You use the JSONSerialization
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:
- The top level object is an
NSArray
orNSDictionary
. - All objects are instances of
NSString
,NSNumber
,NSArray
,NSDictionary
, orNSNull
. - All dictionary keys are instances of
NSString
. - Numbers are not NaN or infinity.
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.