iOS arrays, dictionaries into JSON format uploaded to the background, problems encountered

Source: Internet
Author: User

Project requirements need to be transmitted in JSON format to the background

Turn the dictionary into JSON

Addgoodmodel*model = _dataarray[i];

nsmutabledictionary*guigedict =[nsmutabledictionary dictionary];

[Guigedict setValue: Model. Name forkey:@ "name"];

[Guigedict setValue: Model. Isck forkey:@ "isck"];

[Guigedict setValue:groupprice forkey:@ "Groupprice"];

[Guigedict setValue: Model. Price forkey:@ ' price '];

[Guigedict setValue: Model. Storage Forkey:@ "Storage"];

[Guigedict setValue: [nsstring stringwithformat:@ '%ld ', model. Addgoodid] forkey:@ "id"];

[Guigedict setValue: Model. Commonid forkey:@ "Commonid"];

nsdictionary*parameter [Email protected]{@ "": [[NSString alloc]initwithdata:[nsjsonserialization DataWithJSONObject : Guigedict options:nsjsonwritingprettyprinted Error:nil] encoding:nsutf8stringencoding]};

Caveats: dictionaries cannot be

[Guigedict setobject:@ "" forkey:@ ""]; method, or it will appear garbled.

The array turns into JSON

The array can only be turned into JSON as a string, note that it cannot be a mutable array, only an immutable group

, or there will be a problem

nsarray*jsonarray =[nsarray arraywitharray:_newarray];

nsstring*string =[jsonarray jsonstring];

Note: After receiving the converted JSON format data must receive the assignment with the appropriate type, otherwise the data type does not crash

The array in iOS, the dictionary into JSON format uploaded to the background, problems encountered

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.