Home > AI > IOS > Foundation >

JSONSerialization

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 or NSDictionary.
  • All objects are instances of NSStringNSNumberNSArrayNSDictionary, or NSNull.
  • 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.

Leave a Reply