控制台打印日志,进行调试:
NSDictionary *json = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableContainers error:nil];
[GPBLogger print:@"\n\n******************************************************\n"];
[GPBLogger print:@"\n POST-url: %@ \n == 请求header == \n%@ \n== 请求参数params ==\n%@ \n\n",urlString,task.originalRequest.allHTTPHeaderFields,[[NSString alloc]initWithData:task.originalRequest.HTTPBody encoding:NSUTF8StringEncoding]];
NSString *logString=[[NSString alloc] initWithData:[NSJSONSerialization dataWithJSONObject:json options:NSJSONWritingPrettyPrinted error:nil] encoding:NSUTF8StringEncoding];
[GPBLogger print:@"\n== 请求结果Succeed == \n%@",logString];
[GPBLogger print:@"\n\n******************************************************\n"];
或者:
打开 NSDictionary+**LogHelper.m 文件,添加代码如下(分类)
#import "NSDictionary+**LogHelper.h"
@implementation NSDictionary (**LogHelper)
#if DEBUG
- (NSString *)descriptionWithLocale:(nullable id)locale{
NSString *logString;
@try {
logString=[[NSString alloc] initWithData:[NSJSONSerialization dataWithJSONObject:self options:NSJSONWritingPrettyPrinted error:nil] encoding:NSUTF8StringEncoding];
} @catch (NSException *exception) {
NSString *reason = [NSString stringWithFormat:@"reason:%@",exception.reason];
logString = [NSString stringWithFormat:@"转换失败:\n%@,\n转换终止,输出如下:\n%@",reason,self.description];
} @finally {
}
return logString;
}
#endif
@end