Multiple ways to parse JSON in iOS

Source: Internet
Author: User

I feel JSON parsing, and what's important is the processing of the results after JSON parsing
JSON is parsed as a dictionary, but it is possible to include dictionaries and arrays in the dictionary, which can also contain dictionaries.
Parsing of returned data requested by the client
The following is a brief introduction to the JSON parsing process
Actually, just a word.

"Data is the parsing"!!!!!!!!!!!!!!

Xcode comes with parsing class nsjsonserialization from data to the dictionary
Nsdictionary *weatherdic = [nsjsonserialization jsonobjectwithdata:data options:nsjsonreadingmutableleaves Error: &error];

This is a common JSON parsing method, which is simpler and quicker than the following parsing methods.

Touchjson
Store the parsed content in a dictionary
Nsdictionary *prootdic = [[Cjsondeserializer deserializer]deserialize:data error:&error];
The parse object here is the NSData type

Sbjson
Gets a parser object
Sbjsonparser *parser = [[[Sbjsonparser alloc] init]autorelease];
Gets the dictionary returned after parsing the JSON string
Nsdictionary *rootdic = [parser objectwithstring:string error:&error];
It is important to note that the parsed data is decoded to the NSString type before it can be parsed

Jsonkit
Gets the parsed dictionary (parsing is complete and the return value is the dictionary type)
Nsdictionary *pweatherdic = [jsonstr objectfromjsonstringwithparseoptions:jkparseoptionlooseunicode];//Unified Coding Standard
Note JSONSTR or the data first decoded to the NSString type, then jsonstr directly with the analytic method on the line


It comes with a way to convert data into nsstring types.
NSString *string = [[NSString alloc]initwithdata:data encoding:nsutf8stringencoding];

Multiple ways to parse JSON 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.