IOS converts Nsarray, nsdictionary to JSON format for network transfer

Source: Internet
Author: User

Project, you need to send the Nsarray array to the background, there are spaces inside the result, and the newline cannot recognize

Batchtransnoorder] Line: thecontent:param:{Fromslid=30532; Lccode=G046; Operater=admin; OrderId=ZCG04620171117000004; Toslid=30535; Traycodes=(G04620171106000000287, G04620171101000000180); Whid=192;} Function:__65+[httptask Doposttoserver:needtoken:param:sucessblock:failblock:]_block_invoke Line: theContent: The server-side data received is: {"msg":"[(\ n G04620171106000000287, g04620171101000000180\n)] The pallet data could not be found! ","Success":false}

There are two ways to communicate with the backend:

1 convert Nsarray to JSON string to background

Nsarray *traycodes = @[@ "123",@ "456"*error =  *jsondata = [nsjsonserialization datawithjsonobject:traycodes                                                       options:kniloptions                                                         Error: &ERROR];     *jsonstring = [[NSString alloc] Initwithdata:jsondata                                                 encoding:nsutf8stringencoding];

2 splitting a nsarray into a string with a delimiter

Nsarray *traycodes = @[@ "123",@ "456"*jsonstr = [ Traycodes componentsjoinedbystring:@ ","];

If the array is an object, or a dictionary, refer to: http://blog.csdn.net/worldzhy/article/details/49982491

IOS converts Nsarray, nsdictionary to JSON format for network transfer

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.