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
//The parsed contents are stored in the dictionary
nsdictionary *prootdic = [[Cjsondeserializer deserializer]deserialize:data error:&error];
//The Parse object here is NSData type

//sbjson 
//Get a Parser object  
Sbjsonparser *parser = [[Sbjsonparser alloc] Init]autorelease];
//Get the dictionary returned after JSON string parsing
nsdictionary *rootdic = [parser objectwithstring:string error:&error];
It is important to note that the parsed data is decoded to the NSString type before you can parse the

//jsonkit
//Get the parsed dictionary (complete resolution, return value is dictionary type)
Nsdictionary * Pweatherdic = [JSONSTR objectfromjsonstringwithparseoptions:jkparseoptionlooseunicode];//Unified Coding Standard
//Note Jsonstr or the data first decoded to the NSString type, and then jsonstr directly with the parse method on the line


//Here is a method to convert data to NSString type
NSString *string = [[ NSString Alloc]initwithdata:data encoding:nsutf8stringencoding];

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.