iOS打印AFNetworking中Error错误信息

2018-11-15  本文已影响21人  尕歪Tia

[manager POST:URLString parameters:parameters success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
if (success) {
NSString *resString = [[NSString alloc]initWithData:responseObject encoding:NSUTF8StringEncoding];
success(resString);
}
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
if (error) {
NSData *responseData = error.userInfo[AFNetworkingOperationFailingURLResponseDataErrorKey];
NSString * receive = [[NSString alloc]initWithData:responseData encoding:NSUTF8StringEncoding];

//字符串再生成NSData
NSData *data = [receive dataUsingEncoding:NSUTF8StringEncoding];
NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableLeaves error:nil];
}
}];

上一篇 下一篇

猜你喜欢

热点阅读