error = Error Domain=NSCocoaErrorDomain Code=3840 "Unescaped control character around character 203." UserInfo={NSDebugDescription=Unescaped control character around character 203.}
json在做請(qǐng)求數(shù)據(jù)解析的時(shí)候,部分?jǐn)?shù)據(jù)控制臺(tái)會(huì)輸出上面的一串代碼墩蔓,大概意思是击敌,持有控制字符,在**字節(jié)處愕把。出現(xiàn)這個(gè)問(wèn)題的原因就是:因?yàn)榉?wù)器返回的字符串里面有換行符频鉴,所以我們要在接收到的數(shù)據(jù)里面榄檬,將換行符替換掉,然后再轉(zhuǎn)模型刹悴。但是AFN的GET 或者POST里面并沒(méi)有提供給我們相應(yīng)的數(shù)據(jù)给猾,所以就直接進(jìn)入了
?failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error)
block塊,輸出了錯(cuò)誤信息颂跨。我是這樣解決的:手動(dòng)過(guò)濾掉?“\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];
}