AFNetworking返回NSError时,把com.alamofire.serialization.response.error.data={length = 83, bytes = 0x7b226d73 67223a22 e3809054 4f4b454e ... 61746122 3a22227d }转成NSString类型以便查看。
1.找到AFNetWorking的AFURLResponseSerialization.m 文件
2.添加error.string类型
#ifdef DEBUG
NSString *constAFNetworkingOperationFailingURLResponseStringErrorKey =@"com.alamofire.serialization.response.error.string";
#endif
如下图所示
3.查找
if (data) {
mutableUserInfo[AFNetworkingOperationFailingURLResponseDataErrorKey] = data;
}
替换成 (总共有两个地方要换)
if (data) {
mutableUserInfo[AFNetworkingOperationFailingURLResponseDataErrorKey] = data;
#ifdef DEBUG
mutableUserInfo[AFNetworkingOperationFailingURLResponseStringErrorKey] = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
#endif
}
如图所示
4.在网络请求的方法的 failure打印错误信息
failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
NSLog(@"error_string ==%@", [error userInfo][@"com.alamofire.serialization.response.error.string"]);
}