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