JSON Data Interchange Format in IOS

Source: Internet
Author: User

JSON (JavaScript Object Notation) is a lightweight data interchange format. JSON-specific tutorials can be found in JSON China:http://www.json.org.cn/index.htm , and, of course, the JSON Online validation format tool:http://www.bejson.com/ , you can refer to the other tutorials for further learning about JSON. The lightweight JSON is relative to the structure of the XML document, describing fewer project characters, so the number of characters required to describe the same data is less, of course, the speed of transmission will increase and the flow will be reduced.

Like Weibo, a lot of the data on the microblogging service is JSON, which needs to be parsed locally, because Web and mobile platform development requires as little traffic as possible, and the speed requirement is faster, so JSON becomes the ideal data exchange language.

The process of writing data as a JSON structure is called an "encoding" process, which is a write process. The process of reading data from a JSON document is called a "decoding" process, which is the parsing and reading process.

The following is a list of some common parsing frameworks for JSON:

(1) Sbjson

(2) Touchjson

(3) Yajl, based on the Sbjson, the inside is optimized, the underlying API is written in C, the upper API is objective-c written, the user can have many different choices. It does not support ARC, Source: http://lloyd.github.com/yajl/

(4) Jsonkit

(5) Nextivejson, this framework does not support ARC, Source: Http://github.com/nextive/NextiveJson

(6) Nsjsonserialization, from the naming rules of this framework, I think you guessed it is Apple's own JSON parsing framework, it was iOS5 after the proposed.

Specific simple examples can also refer to this blog: http://blog.csdn.net/enuola/article/details/7903632/Some methods in the iOS7 later version of the warning, it will be modified to iOS7 later support methods.

The following is a simple implementation using Nsjsonserialization to parse, of course, can also use a third-party framework, download the source code, installation, if not supported ARC configuration can be. Parse directly in the Viewdidload method

-(void) viewdidload{[Super viewdidload];//do no additional setup after loading the view, typically from a nib.        Self.navigationItem.leftBarButtonItem = Self.editbuttonitem; Self.detailviewcontroller = (Detailviewcontroller *) [[Self.splitViewController.viewControllers Lastobject]        Topviewcontroller]; [[Nsnotificationcenter Defaultcenter] addobserver:self selector: @selector (Relo                                               AdView:) name:@ "Reloadviewnotification"        Object:nil];    Notesnextivejsonparser *parser = [Notesnextivejsonparser new];    Start parsing [parser start];  nsstring* path = [[NSBundle mainbundle] pathforresource:@ "Test" oftype:@ "json"];        Parse a file called Test.json nsdata *jsondata = [[NSData alloc] initwithcontentsoffile:path];        Nserror *error;                                            ID jsonobj = [nsjsonserialization jsonobjectwithdata:jsondata     Options:nsjsonreadingmutablecontainers error:&error];    if (!jsonobj | | error) {NSLOG (@ "JSON decoding failed");    } self.listdata = [jsonobj objectforkey:@ "Record"]; }

If there is no, also hope pointing!



JSON Data Interchange Format in IOS

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.