error = Error Domain=NSCocoaErrorDomain Code=3840 "Unescaped control character around character 203." UserInfo={NSDebugDescription=Unescaped control character around character 203.}
json在做请求数据解析的时候,部分数据控制台会输出上面的一串代码,大概意思是,持有控制字符,在**字节处。出现这个问题的原因就是:因为服务器返回的字符串里面有换行符,所以我们要在接收到的数据里面,将换行符替换掉,然后再转模型。但是AFN的GET 或者POST里面并没有提供给我们相应的数据,所以就直接进入了
failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error)
block块,输出了错误信息。我是这样解决的:手动过滤掉 “\t” “\n” “\r”
NSURL * URL = [NSURL URLWithString:@"http://*********/****/home/content/showarticle"];
NSURLRequest * request = [NSURLRequest requestWithURL:URL];
NSURLSession * session = [NSURLSession sharedSession];
NSURLSessionDataTask * dataTask = [session dataTaskWithRequest:requestcompletionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError* _Nullable error) {
NSString * str = [[NSString alloc]initWithData:dataencoding:NSUTF8StringEncoding];
NSString * str2 = [str stringByReplacingOccurrencesOfString:@"\t"withString:@""];
str2 = [str2 stringByReplacingOccurrencesOfString:@"\n" withString:@""];
str2 = [str2 stringByReplacingOccurrencesOfString:@"\r" withString:@""];
NSDictionary * userInfo = [NSJSONSerialization JSONObjectWithData:[str2dataUsingEncoding:NSUTF8StringEncoding] options:NSJSONReadingMutableLeaves error:nil];
NSLog(@"%@",userInfo);
}];
[dataTask resume];
}