Returns JSON data from a Foundation object.
- iOS 5.0+
- macOS 10.7+
- tvOS 9.0+
- watchOS 2.0+
JSON data for
nil if an internal error occurs. The resulting data is encoded in UTF-8.
obj will not produce valid JSON, an exception is thrown. This exception is thrown prior to parsing and represents a programming error, not an internal error. You should check whether the input will produce valid JSON before calling this method by using
NSJSONWriting option will generate JSON with whitespace designed to make the output more readable. If that option is not set, the most compact possible JSON will be generated.