JSON data parsing in iOS
The class that the official provides us with to parse the JSON data is Nsjsonserialization, let's first look at some of the methods of this class:
+ (BOOL) Isvalidjsonobject: (id) obj;
Determine if a data object can be converted to JSON data
+ (nsdata *) Datawithjsonobject: (ID) obj options: (nsjsonwritingoptions) opt error: ( Nserror * *) error;
The JSON data is written as NSData data, where the enum parameter is enumerated as follows, this parameter can be set or not set, if set, will output the visual beautiful JSON data, otherwise output compact JSON data.
typedef ns_options (Nsuinteger, nsjsonwritingoptions) {nsjsonwritingprettyprinted = (1UL << 0)}
+ (ID) Jsonobjectwithdata: (nsdata *) Data options: (nsjsonreadingoptions) opt error: ( Nserror * *) error;
This method is the core method of parsing data, which is a JSON data object that can be set to an opt parameter, as follows:
typedef ns_options (Nsuinteger, nsjsonreadingoptions) {//sets resolved arrays and dictionaries to variable objects nsjsonreadingmutablecontainers = (1UL < < 0),//Creates a child node of the parsing data as a mutable string Object nsjsonreadingmutableleaves = (1UL << 1),//allows the topmost layer of the parsed object to be not a dictionary or an array Nsjsonreadi Ngallowfragments = (1UL << 2)}
+ (nsinteger) Writejsonobject: (ID) obj tostream: (nsoutputstream *) stream options: ( Nsjsonwritingoptions) opt error: (nserror * *) error;
Writes the JSON data to the output stream, returning the number of bytes written to the inflow
+ (ID) Jsonobjectwithstream: (nsinputstream *) stream options: (nsjsonreadingoptions) opt Error: (nserror *) error;
Reading JSON data from an input stream
Parsing of JSON data in iOS