Domain=nscocoaerrordomain code=3840 "unescaped control character around character 203." Userinfo={ns__ theory

Source: Internet
Author: User

Error = Error Domain=nscocoaerrordomain code=3840 "unescaped control character around character 203." userinfo={nsdebugdescription=unescaped control character around character 203.}

JSON when parsing the request data, some data consoles output a string of code above, presumably meaning, holding the control character at the * * byte. The reason for this problem is that because there are line breaks in the string returned by the server, we need to replace the newline character in the received data and then turn the model back. But AFN's get or post did not provide us with the corresponding data, so we went directly into the

failure:^ (Nsurlsessiondatatask * _nullable task, Nserror * _nonnull error) block, output error message. I solved it by manually filtering out "\ n" "\ r"


Nsurl * URL = [Nsurl urlwithstring:@ "http://*********/****/home/content/showarticle"];

Nsurlrequest * request = [nsurlrequest Requestwithurl:url];

Nsurlsession * session = [nsurlsession sharedsession];

Nsurlsessiondatatask * Datatask = [session datataskwithrequest:request completionhandler:^ (NSData * _Nullable data, Nsurlresponse * _nullable response, Nserror * _nullable error) {

NSString * str = [[NSString alloc]initwithdata:data encoding:nsutf8stringencoding];

NSString * str2 = [str stringbyreplacingoccurrencesofstring:@ "T" withstring:@ "];

STR2 = [str2 stringbyreplacingoccurrencesofstring:@ "\ n" withstring:@ "];

STR2 = [str2 stringbyreplacingoccurrencesofstring:@ "\ r" withstring:@ "];

Nsdictionary * UserInfo = [nsjsonserialization jsonobjectwithdata:[str2 datausingencoding:nsutf8stringencoding] Options:nsjsonreadingmutableleaves Error:nil];

NSLog (@ "%@", userInfo);

}];

[Datatask resume];

The output dictionary can be parsed directly

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.