您的位置:首页 > 大数据 > 人工智能

error = Error Domain=NSCocoaErrorDomain Code=3840

2015-12-06 17:29 926 查看
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。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: