IOS json parsing encounters error: Error Domain = NSCocoaErrorDomain Code = 3840 & amp; quot; The operation couldn't be completed.

Source: Internet
Author: User

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 Round character 1419 .}


Previously, json was parsed in standard format, and no tabs such as \ n \ r \ t were found in json data.

During the parsing today, we found that json resolution is good or bad, and there is also a problem with online json resolution. After searching for half a day, I finally found that the tabs are playing a strange role, because the standard json parsing does not allow these tabs. Therefore, when receiving the heat preservation, We need to filter out these tabs.

NSString * responseString = [requestresponseString];

ResponseString = [responseString stringByReplacingOccurrencesOfString: @ "\ r \ n" withString: @ ""];

ResponseString = [responseString stringByReplacingOccurrencesOfString: @ "\ n" withString: @ ""];

ResponseString = [responseString stringByReplacingOccurrencesOfString: @ "\ t" withString: @ ""];

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

SBJsonParser * parser = [[SBJsonParseralloc] init] autorelser];

Id returnObject = [parser objectWithString:ResponseString];

NSDictionary * userInfo = nil;

NSArray * userArr = nil;

If ([returnObject isKindOfClass: [NSDictionary class]) {

If (userInfo ){

[UserArrrelease];

}

UserInfo = (NSDictionary *) returnObject;

}

Else if ([returnObjectisKindOfClass: [NSArrayclass]) {

UserArr = (NSArray *) returnObject;

}

NSError * e = nil;



// Resolution method provided by the system.

NSDictionary *UserInfo = [NSJSONSerializationJSONObjectWithData: [jsonString dataUsingEncoding: NSUTF8StringEncoding] options: NSJSONReadingMutableLeaveserror: & 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.