error = Error Domain=NSCocoaErrorDomain Code=3840
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的更多相关文章
- 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 ...
- iOS解析JSON字符串报错Error Domain=NSCocoaErrorDomain Code=3840 "Invalid escape sequence around character 586."
将服务器返回的JSON string转化成字典时报错: Error Domain=NSCocoaErrorDomain Code=3840 "Invalid escape sequence ...
- 【iOS】iOS Error Domain=NSCocoaErrorDomain Code=3840 "未能完成操作。(“Cocoa”错误 3840。)"
昨天遇到的这个问题,详细信息: ----->类和方法__25+[Manager noticeRequest:]_block_invoke399----->错误信息Error Domain= ...
- 报错Domain=NSCocoaErrorDomain Code=3840 "Garbage at end."
网络请求出现报错:Domain=NSCocoaErrorDomain Code=3840 "Garbage at end." 出现的问题是后台返回了两次json数据!
- 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 ...
- NSJSONSerialization 反序列化失败 NSCocoaErrorDomain Code=3840
NSJSONSerialization 反序列化失败 NSCocoaErrorDomain Code=3840 NSCocoaErrorDomain Code=3840 “No string key ...
- afnetworking NSCocoaErrorDomain Code=3840 解决
afnetworking json解析出错 解决方法1 AFURLResponseSerialization.m 258行修改 responseString = [responseString str ...
- DeviceToken 获取失败,原因:Error Domain=NSCocoaErrorDomain Code=3000 "未找到应用程序的“aps-environment”的授权字符串"...
apns -> 注册推送功能时发生错误, 错误信息: Error Domain=NSCocoaErrorDomain Code=3000 "未找到应用程序的“aps-environme ...
- Error in registration. Error: Error Domain=NSCocoaErrorDomain Code=3000 "未找到应用程序的“aps-environment”的授
本文转载至 http://blog.csdn.net/woaifen3344/article/details/41311023 Code3000极光推送erroryour certificate n ...
随机推荐
- 【BZOJ】2209: [Jsoi2011]括号序列(splay)
http://www.lydsy.com/JudgeOnline/problem.php?id=2209 splay又犯逗........upd1那里的sum忘记赋值反............. 本题 ...
- 转 c# 日期函数[string.Format----GetDateTimeFormats]格式 .
DateTime dt = DateTime.Now;Label1.Text = dt.ToString();//2005-11-5 13:21:25Label2.Text = dt.ToFileTi ...
- System.getProperty
我们可以通过System.getProperty("user.home")读取JAVA系统的user.home属性的值.
- ubuntu + subversion + apache2 设置
1.下载安装subversion,apache2 sudo apt-get updatesudo apt-get upgrade sudo apt-get install apache2sudo a ...
- Mongodb 创建索引
db.getCollection('ct_project').ensureIndex({'pro_code':1}) 创建索引 db.getCollection('ct_project').ensu ...
- NBUT 1028 该减肥了(简单递推)
[1028] 该减肥了 时间限制: 1000 ms 内存限制: 65535 K 问题描述 由于长期缺乏运动,Teacher Xuan发现自己的身材臃肿了许多,于是他想健身,更准确地说是减肥.Teach ...
- metasploit--payload模块信息
Name Disclosure Date Rank Description ---- ...
- CSS2系列:BFC(块级格式化上下文)IFC(行级格式化上下文)
BFC 块级格式化上下文,不好理解,我们暂且把她理解成"具有特殊的一类元素" 哪些元素会生成BFC? 根元素 float属性不为none position为absolute或fix ...
- php连接redis数据库 操作redis任务队列
首先你的安装phpredis扩展在你的服务器上 $redis = new Redis(); $redis->connect('119.29.10.xx',6379); $redis->au ...
- 【翻译】KNACK制作介绍
KNACK 次世代游戏机的性能开发新世界,PlayStation 4首发游戏的舞台幕后 配合PS4的国内首发,作为SCE的第一个游戏发售的本作. 一边加入发挥次世代机机能的表现,设计了谁都可以 ...