Parsing of JSON data in iOS

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.