IOS JSON parsing encounters Error:error Domain=nscocoaerrordomain code=3840 "The operation couldn ' t be completed.__ programming

Source: Internet
Author: User

The Error domain=nscocoaerrordomain code=3840 "The operation couldn ' t be completed. (Cocoa error 3840.) " (unescaped control character around character 1419.) userinfo=0x1563cdd0 {nsdebugdescription=unescaped control character around character 1419.}


Before parsing JSON is a standard format, there is no \ r \ n \ \ t tab in the JSON data.

Today, when parsing, I found that JSON parsing is good and bad, with online JSON parsing is also a problem. Looking for a long time finally found that the tab in the mischief, because the standard JSON parsing is not allowed to have these several tabs. So we need to filter out these tabs when we receive the insulation.

NSString * responsestring = [request responsestring];

responsestring = [responsestring stringbyreplacingoccurrencesofstring:@ "\ r \ n" withstring:@ "];

responsestring = [responsestring stringbyreplacingoccurrencesofstring:@ "\ n" withstring:@ "];

responsestring = [responsestring stringbyreplacingoccurrencesofstring:@ "T" "withstring:@"];

NSLog (@ "responsestring =%@", responsestring);

Sbjsonparser *parser = [[[Sbjsonparser Alloc]init] autorelease];

ID returnobject = [parser objectwithstring:responsestring];

Nsdictionary *userinfo = nil;

Nsarray *userarr = nil;

if ([Returnobject Iskindofclass:[nsdictionary class]]) {

if (userInfo) {

[Userarr release];

}

UserInfo = (nsdictionary*) returnobject;

}

else if ([Returnobject Iskindofclass:[nsarray class]]) {

Userarr = (nsarray*) returnobject;

}

nserror* e = nil;



The method of parsing the system itself.

nsdictionary * userInfo = [nsjsonserialization jsonobjectwithdata:[jsonstring datausingencoding: Nsutf8stringencoding] Options:nsjsonreadingmutableleaves error:&e];

if (e) {

NSLog (@ "%@", e);

}


Related Article

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.