Error = 3840 when parsing data in iOS and error3840 when parsing data in ios

Source: Internet
Author: User

Error = 3840 when parsing data in iOS and error3840 when parsing data in ios

1. An error occurred while parsing the JSon data format.

Unescaped control character around character XXXX

And The data couldn 'tbe read because it isn' t in the correct format.

Error code 3840

In this case, it is generally caused by non-standard json data, which may be caused by escape characters in json data, such as/t/n/0.

 

Solution to nonstandard data: 1. modify data in the background

 

2. Determine the data in your project and take the AFNetWorking library for data download.

 

// Download the data to be searched

AFHTTPRequestOperationManager * manager = [AFHTTPRequestOperationManager];

Manager. responseSerializer = [AFHTTPResponseSerializer serializer];

[Manager GET: urlString parameters: nil success: ^ (AFHTTPRequestOperation * operation, id responseObject ){

NSString * str = [[NSString alloc] initWithData: responseObject encoding: NSUTF8StringEncoding];

NSString * str2 = [str stringByReplacingOccurrencesOfString: @ "\ t" withString: @ ""];

Str2 = [str2 stringByReplacingOccurrencesOfString: @ "\ n" withString: @ ""];

Str2 = [str2 stringByReplacingOccurrencesOfString: @ "\ r" withString: @ ""];

NSDictionary * dict = [NSJSONSerialization JSONObjectWithData: [str2 dataUsingEncoding: NSUTF8StringEncoding] options: NSJSONReadingMutableContainers error: nil];

 

Parses the parsed NSData into a string to determine whether the data contains these escape characters. If the data contains these escape characters, replace them with an empty string and convert the string to NSData, then parse the data into JSon data.

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.