JSON data exchange format in iOS, iosjson

Source: Internet
Author: User

JSON data exchange format in iOS, iosjson

JSON (JavaScript Object Notation) is a lightweight data exchange format. JSON specific tutorial, can see JSON China: http://www.json.org.cn/index.htm, of course there is JSON online validation formatting tool: http://www.bejson.com/, hope to learn more JSON can refer to other tutorials. The lightweight JSON is relative to the XML document structure, and the description project has fewer characters, so the number of characters required to describe the same data is less, of course, the transmission speed will increase and the traffic will decrease.

For Weibo, a lot of Weibo server data is JSON, and the data returned from these requests must be parsed locally. Because Web and mobile platform development requires as little traffic as possible, JSON becomes the ideal data exchange language.

The process of writing data into a JSON structure is called the "encoding" process, that is, the writing process. The process of reading and processing data from the JSON document is called the "decoding" process, that is, the parsing and reading process.

The following lists some common JSON parsing frameworks:

(1) SBJson

(2) TouchJSON

(3) YAJL, which is based on SBJson, is optimized. The underlying API is written in C, and the upper API is written in objective-c. You can have different options. It does not support ARC, source: http://lloyd.github.com/yajl/

(4) JSONKit

(5) NextiveJson, this framework does not support ARC, source code: http://github.com/nextive/NextiveJson

(6) NSJSONSerialization: According to the naming rules of this framework, you may have guessed that it is Apple's own JSON parsing framework, which was proposed after iOS5.

Specific simple examples can also refer to this blog: some methods of http://blog.csdn.net/enuola/article/details/7903632/ in iOS7 later versions there will be a warning, change it to iOS7 after the support of the method can be.

The following is a simple implementation of NSJSONSerialization for parsing. Of course, you can also use a third-party framework to download the source code and install it. If it does not support ARC configuration, you can. Parse directly in the viewDidLoad Method

-(Void) viewDidLoad {[super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. self. navigationItem. leftBarButtonItem = self. editButtonItem; self. detailViewController = (DetailViewController *) [[self. splitViewController. viewControllers lastObject] topViewController]; [[nsicationcenter center defacenter center] addObserver: self selector: @ selector (reloadView :) name: @ "reloa DViewNotification "object: nil]; NotesNextiveJsonParser * parser = [NotesNextiveJsonParser new]; // start parsing [parser start]; NSString * path = [[NSBundle mainBundle] pathForResource: @ "Test" ofType: @ "json"]; // parse a file named Test. json file NSData * jsonData = [[NSData alloc] initWithContentsOfFile: path]; NSError * error; id jsonObj = [NSJSONSerialization JSONObjectWithData: jsonData options: NSJSONReadingMutableContaine Rs error: & error]; if (! JsonObj | error) {NSLog (@ "JSON decoding failed");} self. listData = [jsonObj objectForKey: @ "Record"];}

If anything is wrong, please give me some advice!




The JSON data format is as follows:

JSON is a lightweight data exchange format. Json is simply an object and an array in js. Therefore, the two structures are objects and arrays. The data format you use is the composite structure of objects and arrays.
The JSON data in your example is a name/value pair. There is only one "wegInstLt" variable name, and the value contains an array of items. Assume var info = {"wegInstLt": [{"billTypeCode": "0", "channelId": 530, "channelKind": "03", "isHaveBillDate ": "0", "isHavePayAmount": "0", "isLeePay": "0", "isPrePay": "1", "wiliCode": "1238", "wiliItem ": "00", "wiliName": "Harbin tap water company", "wltiId": 10345}]}; to get "Harbin tap water company", you can write as follows:
Info. wegInstLt [0]. wiliName
Hope to help you and wish you a happy life!

What is JSON used? Lightweight data exchange format?

From Baidu encyclopedia

JSON construction has two structures:
Json is simply an object and an array in javascript. Therefore, the two structures are objects and arrays. These two structures can represent various complex structures.
1. Object: the expanded content of the object represented as "{}" in js. The data structure is
{Key: value, key: value ,...} the structure of key-value pairs. In the object-oriented language, key is the object attribute, and value is the corresponding attribute value, so it is easy to understand
Solution: The value method is to get the property value of the object. key. the type of the property value can be numbers, strings, arrays, and objects.
2. array: The array is expanded by brackets "[]" in js. The data structure is ["java", "javascript", "vb",...], the value can be obtained using indexes in the same way as in all languages. Field values can be of the following types: Numbers, strings, arrays, and objects.
After the object and array structures, you can combine them into complex data structures.

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.