ios AFN解决输出错误信息的办法

在iOS开发中使用AFN进行网络请求时经常会有请求报错,信息错误提示信息如下:

{ Status Code: 422, Headers {
"Access-Control-Allow-Origin" : [
"*"
],
"Content-Type" : [
"application/json"
],
"Pragma" : [
"no-cache"
],
"Server" : [
""
],
"X-Powered-By" : [
"PHP/7.2.6"
],
"Date" : [
"Thu, 11 Apr 2019 02:54:10 GMT"
],
"Keep-Alive" : [
"timeout=58"
],
"Cache-Control" : [
"no-cache"
],
"Transfer-Encoding" : [
"Identity"
]

正常情况下,作为开发人员是能找到错误原因的,但是如果不做处理的话,没办法给用户提示,处理方法:

最后加了如下这样代码的,输出才正常:

NSData *errorData = error.userInfo[AFNetworkingOperationFailingURLResponseDataErrorKey];
NSDictionary *serializedData = [NSJSONSerialization JSONObjectWithData: errorData options:kNilOptions error:nil];
NSLog(@"error--%@",serializedData);

你可能感兴趣的:(ios AFN解决输出错误信息的办法)