json解析,同样的请求,有一个请求,无反应。纠结了几天,终于解决了。

error = Error Domain=NSCocoaErrorDomain Code=3840 "Unescaped control character around character 168." UserInfo={NSDebugDescription=Unescaped control character around character 168.}

报错信息如上:

这个原因,是因为服务器返回的字符串里面有换行符,所以我们要在接收到的数据里面,将换行符替换掉,然后再转模型。

但是,AFN解析,并没有提供原有的数据给我们(我没找),就直接去了error 的接口。

然后用session的dataTask,用字符串转它返回的data,则能够把数据读取出来,打印,果然有换行符。于是,改写了原来的方法,用session去代替。

    NSString * url = infoCategoryM.listUrl;
NSURL * URL = [NSURL URLWithString:url];
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:@""]; ContentListArrM * contentListArrM = [[ContentListArrM alloc]initWithString:str2 error:nil];
[self.contentListArr removeAllObjects];
for (int i = 0; i < contentListArrM.contentList.count ; i++) {
ContentListM * m = [contentListArrM.contentList objectAtIndex:i];
if (![XSDKResourceUtil xsdkstringIsnilOrEmpty:m.title]) {
[self.contentListArr addObject:m];
}
}
dispatch_async(dispatch_get_main_queue(), ^{
[self.infoTableView reloadData];
self.selectedButton.selected = NO;
selectedButton.selected = YES;
self.selectedButton = selectedButton;
NewsTableViewCell * cell = [self.infoTableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:1 inSection:0]];
cell.selected = YES;
}); }];
[dataTask resume];

  里面,替换掉了换行符等其他字符,然后再转模型。

This application is modifying the autolayout engine from a background thread, which can lead to engine corruption and weird crashes.  This will cause an exception in a future release.

这个错误,是告诉我们,要在主线程里面更新UI。

error = Error Domain=NSCocoaErrorDomain Code=3840的更多相关文章

  1. iOS json 解析遇到error: Error Domain=NSCocoaErrorDomain Code=3840 "The operation couldn’t be completed.

    Error Domain=NSCocoaErrorDomain Code=3840 "The operation couldn’t be completed. (Cocoa error 38 ...

  2. iOS解析JSON字符串报错Error Domain=NSCocoaErrorDomain Code=3840 "Invalid escape sequence around character 586."

    将服务器返回的JSON string转化成字典时报错: Error Domain=NSCocoaErrorDomain Code=3840 "Invalid escape sequence ...

  3. 【iOS】iOS Error Domain=NSCocoaErrorDomain Code=3840 "未能完成操作。(“Cocoa”错误 3840。)"

    昨天遇到的这个问题,详细信息: ----->类和方法__25+[Manager noticeRequest:]_block_invoke399----->错误信息Error Domain= ...

  4. 报错Domain=NSCocoaErrorDomain Code=3840 "Garbage at end."

    网络请求出现报错:Domain=NSCocoaErrorDomain Code=3840 "Garbage at end." 出现的问题是后台返回了两次json数据!

  5. NSCocoaErrorDomain Code=3840 "The operation couldn’t be completed. (Cocoa error 3840.)"

    原文: http://stackoverflow.com/questions/19874935/afnetworking-2-0-post-issue-cocoa-error-3840json-tex ...

  6. NSJSONSerialization 反序列化失败 NSCocoaErrorDomain Code=3840

    NSJSONSerialization 反序列化失败 NSCocoaErrorDomain Code=3840  NSCocoaErrorDomain Code=3840 “No string key ...

  7. afnetworking NSCocoaErrorDomain Code=3840 解决

    afnetworking json解析出错 解决方法1 AFURLResponseSerialization.m 258行修改 responseString = [responseString str ...

  8. DeviceToken 获取失败,原因:Error Domain=NSCocoaErrorDomain Code=3000 "未找到应用程序的“aps-environment”的授权字符串"...

    apns -> 注册推送功能时发生错误, 错误信息: Error Domain=NSCocoaErrorDomain Code=3000 "未找到应用程序的“aps-environme ...

  9. Error in registration. Error: Error Domain=NSCocoaErrorDomain Code=3000 "未找到应用程序的“aps-environment”的授

     本文转载至 http://blog.csdn.net/woaifen3344/article/details/41311023 Code3000极光推送erroryour certificate n ...

随机推荐

  1. 【wikioi】1269 匈牙利游戏(次短路+spfa)

    http://www.wikioi.com/problem/1269/ 噗,想不到.. 次短路就是在松弛的时候做下手脚. 设d1为最短路,d2为次短路 有 d1[v]>d1[u]+w(u, v) ...

  2. CentoS 下安装gitlab

    curl https://raw.github.com/mattias-ohlsson/gitlab-installer/master/gitlab-install-el6.sh | bash 报错 ...

  3. iOS完整学习步骤

    一  C语言 1.1基本数据类型和基本运算 1.2 函数 数组 字符串 指针 1.3 预处理指令 1.4结构体 枚举 1.5 文件操作 内存管理 二 Objective - C 2.1 面向对象 2. ...

  4. Odoo 外协加工产品的实现

    需求,当前有产品A需要讲原料B.C送到加工厂P,由加工厂P加工完成后送回公司,然后再销售给客户. 1.首先,设置产品A的BOM由原料B,C组成,产品A的Route设置为Manufacture,产品A的 ...

  5. 连接mysql遇到的问题

    1. 首先使用一个用户名不行时,可以新建一个用户名点击用户,输入名和密码,此时一定要记住密码,别忘了.不过也可以点击编辑用户改.此时连接时发现还是连接不上.出现错误信息为: Access denied ...

  6. php 获取当前脚本的url的案例

    关于用php 获取当前脚本的url很多朋友会说很简单,但是要获取很详细的就要经过多次判断. $PHP_TIME = time();$PHP_SELF = isset($_SERVER['PHP_SEL ...

  7. sonarqube  安装配置

    http:// www.sonarqube.org MySQL Unsupported mysql version: 5.5. Minimal supported version is 5.6. Th ...

  8. POJ 1182 食物链(种类并查集)

    食物链 Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 63592   Accepted: 18670 Description ...

  9. Oracle11g创建表空间语句

    在plsql工具中执行以下语句,可建立Oracle表空间. /*分为四步 *//*第1步:创建临时表空间  */create temporary tablespace yuhang_temp temp ...

  10. twitter storm源码走读之1 -- nimbus启动场景分析

    欢迎转载,转载时请注明作者徽沪一郎及出处,谢谢. 本文详细介绍了twitter storm中的nimbus节点的启动场景,分析nimbus是如何一步步实现定义于storm.thrift中的servic ...