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。

上一篇:[转] PostgreSQL学习手册(函数和操作符)


下一篇:java equals()方法