iOS Development topic--conversion parsing JSON format for character formatting (native class library parsing)

Source: Internet
Author: User

1, do not waste time, this code through the practice of testing through!

// Network Request code snippet

//post Request

    nsurl * url=[ nsurl urlwithstring : @ "Http://192.168.253.101:8080/ERP/mobile/login.action" ];

nsmutableurlrequest *request =[[nsmutableurlrequestalloc] Initwithurl: URLcachepolicy:nsurlrequestuseprotocolcachepolicytimeoutinterval: ];

// Set Request mode

[RequestSethttpmethod:@ "POST"];

// Set parameters

nsstring *str=@ "Username=a023&password=1&master=uas";

nsdata *data=[strdatausingencoding:nsutf8stringencoding];

[RequestSethttpbody:d ATA];

// connection Server

nsdata *received=[nsurlconnectionsendsynchronousrequest: Request Returningresponse:nilerror:nil];

nsstring *strl=[[nsstringalloc]initwithdata: Received encoding:nsutf8stringencoding];

//NSLog (@ " result:%@", Strl); ---Custom JSON format string containing collections and arrays in the form of native class library parsing

nserror *error;

nsstring *temstr=@ "{\" count\ ": 50,\" allprocess\ ": [{\" name\ ": \" Holy Angels \ "},{\" Name\ ": \" commodity angel \ "},{\" name\ ": \" beautiful angel \ "}]}";

NSLog (@ "temstr=%@", TEMSTR);

nsdata *rdata=[temstrdatausingencoding:nsutf8stringencoding];

NSLog (@ "rdata=%@", rdata);

nsdictionary *json=[temstrobjectfromjsonstringwithparseoptions: Jkparseoptionlooseunicode];

NSLog (@ "json=%@", JSON);

nsarray *elist=[json objectforkey:@ "allprocess"];

nsstring *uu=[elist objectatindex:1];

nsstring *u_name=[[elist objectatindex:1] objectforkey:@ "name"];

NSLog (@ "elist=%@", Elist);

NSLog(@ "elist=%@", UU);

NSLog (@ "elist=%@", U_name);

for (int i=0; i<[elistcount];i++) {

NSLog(@ " traversing array \ n%i=%@", I,[[elistobjectatindex: i] o Bjectforkey:@ "name"]);

}

iOS Development topic--conversion parsing JSON format for character formatting (native class library 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.