iOS parsing data when error=3840

Source: Internet
Author: User

1. Parsing problems with JSON data format error

unescaped control character around character XXXX

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

Error code is 3840

When this happens, it is generally caused by the non-specification in the JSON data, the presence of an escape character in the JSON data may cause this, such as a/t/n/0, etc.

Data is less canonical workaround: 1. Background modification Data

2. Judging the data in your own project, take afnetworking when the library downloads data

Download the data you need to search

Afhttprequestoperationmanager *manager = [Afhttprequestoperationmanager manager];

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];

Parse the resulting NSData data into a string form, determine whether the data contains these escape characters, the words are replaced with an empty string, and then convert the string to the NSData type of data, and then parse it into JSON data.

iOS parsing data when error=3840

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.