iOS pass JSON string there's an equal sign in front of you.

Source: Internet
Author: User

Let me ask you a question.

Backstage let me take the request parameter into a body into a JSON string into the body passed to him, of course, the header is set, set up in advance,

But then it became known that the essence of turning entities into JSON strings was to first convert entities to dictionaries or arrays and then use

NSData *jsondata = [nsjsonserialization datawithjsonobject:model options:nsjsonwritingprettyprinted Error:nil];

//

NSString *jsonstr = [[NSString alloc] Initwithdata:jsondata encoding:nsutf8stringencoding];

The above two lines of code parse the conversion to get a really good JSON string.

But the problem arises, the output of the log JSON string before each pass is no problem, but to the server, there is a JSON string before the equal sign,

=%3c7b0a2020%2022706173%2073776f72%206422203a%2020223132%2033343536%20222c0a20%2020227573%2065724e61% 206d652220%203a202231%2033323431%2035383235%203233220a%207d%3e

The background cannot parse.

I found the reason for finding AFN bottom.

AFURLREQUESTSERIALIZATION.M 508 Lines

query = afquerystringfromparameters (parameters); The clear output has changed our JSON (why it changed).

Solutions

Afhttpsessionmanager 267 Line method to add

[Request Sethttpbody:parameters]; (I don't know why),

But until now, the data has not yet been changed to the previous JSON string to the JSON stream is deleted nsstring *jsonstr = [[NSString alloc] Initwithdata:jsondata encoding:nsutf8string Encoding];

But I'm using ytknetwork, so I changed.

YTKNETWORKAGENT.M 167 line Sessiontaskforrequest into the response post (can be get if needed), that is, 457 lines

In the Datataskwithhttpmethod method, add

[Request Sethttpbody:parameters]; This line of code

It's finally over.

iOS pass JSON string there's an equal sign in front of you.

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.