How IOS uploads JSON data by post

Source: Internet
Author: User

today in the project, engaged in a morning time to upload a JSON string data, communication with the background n times no results, careful study of their data structure and background interface data structure, found that the data format is not a problem, the background provides the interface format as follows:
I use the dictionary array way, the key value "name", "StartTime" corresponds to the string, to the background is correct, and then the key corresponding to "data" is a list, then the array is a dictionary, key is "medicine", "num", "diet_ Time", (PS: I use is afnetworking), to backstage, always be backstage parsing into other formats, depressed a morning, always feel should in which place value turn, turn into JSON format, but can't think out, then Baidu can not find corresponding. Finally, thanks to my colleague, Xiao Dong reminded me that he had a similar situation before uploading, and asked me to look at his plan:
Nserror *error; NSData *jsondata = [nsjsonserialization datawithjsonobject:data options:nsjsonwritingprettyprinted Error:&error] ;//Here The data parameter is an array of key "data" that I mentioned above nsstring *jsonstring = [[NSString alloc] initwithdata:jsondata encoding: Nsutf8stringencoding];
Then put this jsonstring to the key "data" corresponding to the value, upload, done!This method can also be used when using ASIHTTPRequest to request a network. If I had known, I would not have wasted a morning's time, and had to write it down.

How IOS uploads JSON data by post

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.