JSON parsing scheme, json Parsing

Source: Internet
Author: User

JSON parsing scheme, json Parsing

 

In iOS, there are four common JSON resolution solutions.

Third-party frameworks: JSONKit, SBJson, and TouchJSON (performance from left to right, the worse)

Apple native (built-in): NSJSONSerialization (Best Performance)

 

Conversion between JSON and OC

JSON-> OC object

  NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&error];

Use this class to parse the first parameter data in json format,

The second parameter: Operation: Generally, NSJSONReadingMutableContainers or kNilOptions is written. The latter has the highest efficiency. The former requires a variable container.

Third parameter: Incorrect address

 

OC Object> JSON

  NSData *data = [NSJSONSerialization dataWithJSONObject:@{@"name":@"jack"}]  options:NSJSONWritingPrettyPrinted error:nil];

 

 

To Format JSON data, you can write it to a plist file.

// Parse JSON NSDictionary * dict = [NSJSONSerialization JSONObjectWithData: data options: kNilOptions error: nil]; [dict writeToFile: @ "/Users/DDZ/Desktop/data. plist "atomically: YES];

 

Related Article

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.