2016-1-JSON parsing

Source: Internet
Author: User

One: JSON

1. What is JSON

1.1 JSON is a lightweight data format that is typically used for data interaction.

1.2 The data returned to the client by the server is usually in JSON or XML format (except for file downloads).

2. The JSON format is much like the dictionary and array in OC

2.1 Note that the key in the JSON must be in double quotes!

3. To mine data from JSON, you must parse the JSON.

3.1 JSON---OC conversion table

Two: JSON parsing scheme

1.json-oc Object

+ (nullable ID) Jsonobjectwithdata: (nsdata *) Data options: (nsjsonreadingoptions   Opt error: (nserror *) error;

Note that the ID type is returned

2. Code:

Nsurl *url = [Nsurl urlwithstring:@"http://120.25.226.186:32812/login?usename=520it&pwd=520it"]; Nsurlrequest*request =[Nsurlrequest Requestwithurl:url]; [Nsurlconnection sendasynchronousrequest:request queue:[nsoperationqueue Mainqueue] CompletionHandler:^ (Nsurlresponse * _nullable response, NSData * _nullable data, Nserror *_nullable Connectionerror) {        //parsing JSONNsdictionary *dic =[nsjsonserialization jsonobjectwithdata:data options:kniloptions Error:nil]; NSLog (@"%@", dic[@"Error"]); }];

2016-1-JSON parsing

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.