basic use of JSON in A.ios
1. Parsing JSON data(1) JSON deserialization
Object
{}
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 nested (2) JSON tools starting with iOS 5, using nsjsonserialization for JSON parsing
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 & deserialization
deserialization
[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"]; -}
[IOS Multithreading & Networking-2.1]-parsing JSON