zoukankan      html  css  js  c++  java
  • 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:@"	" withString:@""];
            str2 = [str2 stringByReplacingOccurrencesOfString:@"
    " withString:@""];
            str2 = [str2 stringByReplacingOccurrencesOfString:@"
    " 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。

  • 相关阅读:
    CH1301 邻值查找【set应用】
    poj1185 炮兵阵地【状压DP】
    codeforces#516 Div2---ABCD
    2017ACM-ICPC沈阳区域赛
    poj2411 Mondriaan's Dream【状压DP】
    hdu2196 Computer【树形DP】【换根法】
    poj3345 Bribing FIPA【树形DP】【背包】
    poj1463 Strategic game【树形DP】
    poj1191 棋盘分割【区间DP】【记忆化搜索】
    CH5E09 能量相连【区间DP】
  • 原文地址:https://www.cnblogs.com/tanglimei/p/5023937.html
Copyright © 2011-2022 走看看