[IOS Multithreading & Networking-2.1]-parsing JSON

Source: Internet
Author: User

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

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.