Shimen the main contribution, respect the work of the author, please do not reprint.
If the article is helpful to you, you are welcome to donate to the author, support the Shimen, donate the amount at random, ^_^
I want to donate: Click Donate
Cocos2d-x source Download: Dot I teleport
Games Official Download:HTTP://DWZ.CN/RWTJL
Game video preview:http://dwz.cn/RzHHd
Game Development Blog:Http://dwz.cn/RzJzI
Game Source Transfer : Http://dwz.cn/Nret1
basic use of JSON in A.ios1. Parsing JSON data(1) JSON deserializationObject
{}
Structure of the key-value pairs for format {key:value, Key:value,...}
Can be deserialized into nsdictionary in OC
Array
[]
format ["Java", "JavaScript", "VB",...]
Can be deserialized into nsarray in OC
Tips
The JSON data format is very similar to the fast wrapping method in OC
The JSON data format also supports nesting (2) JSON toolStarting with iOS 5, use Nsjsonserialization to parse JSON
Other common three kinds of JSON parsing third-party libraries:
Sbjson because the API is easy to use, there may be some applications that remain
Jsonkit Jsonkit's developers say: Jsonkit's performance is better than Apple
Touchjson (3) Serialization & deserializationDeserialization
[Nsjsonserialization jsonobjectwithdata:data options:0 error:null];
Serialization of
[nsjsonserialization Datawithjsonobject:array options:0 error:null]; Sample:
1 //Send messages synchronously2NSData *data =[nsurlconnection sendsynchronousrequest:request returningresponse:nil Error:nil];3 4 //parsing Data5 if(data) {//Get Return Data6 //Unblock screen lock7 [Mbprogresshud Hidehud];8 9 //parsing JSON dataTenNsdictionary *dict =[nsjsonserialization jsonobjectwithdata:data options:nsjsonreadingmutableleaves Error:nil]; One A //processing the returned data -NSString *result = dict[@"Success"]; - if(Result) { the [Mbprogresshud Showsuccess:result]; -}Else { -result = dict[@"Error"]; - if(Result) { + [Mbprogresshud Showerror:result]; - } + } A}Else { at[Mbprogresshud ShowError:@"the Internet is busy, please try again later"]; -}
Shimen the main contribution, respect the work of the author, please do not reprint.
If the article is helpful to you, you are welcome to donate to the author, support the Shimen, donate the amount at random, ^_^
I want to donate: Click Donate
Cocos2d-x source Download: Dot I teleport
Games Official Download:HTTP://DWZ.CN/RWTJL
Game video preview:http://dwz.cn/RzHHd
Game Development Blog:Http://dwz.cn/RzJzI
Game Source Transfer : Http://dwz.cn/Nret1
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Analysis of iOS multi-threading and network development JSON data