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