一:对返回的Json数据输出进行转化成中文状态输出
操作如下:
对Json数据里的字典类型进行拓展转化,创建一个NSDictionary类 Category类型文件。
#import <Foundation/Foundation.h>
@interface NSDictionary (Log)
@end
#import "NSDictionary+Log.h"
@implementation NSDictionary (Log)
- (NSString *)descriptionWithLocale:(nullable id)locale{
NSString *logString;
@try {
//这里做一下处理判断,可以过滤一些输出造成莫名的闪退
if (![locale isEqual:[NSNull alloc]]) {
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;
}
@end
使用 //data :返回来的数据
NSMutableDictionary *dictionary = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
NSLog(@"==data===%@",[dictionary descriptionWithLocale:dictionary[@"data"]]);
二:对输出进行定位监控
#ifdef DEBUG
//输出,定位到具体类,函数,代码行数
#define Log(format, ...) fprintf(stderr,"%s:%d\t%s\n",[[[NSString stringWithUTF8String:__FILE__] lastPathComponent] UTF8String], __LINE__, [[NSString stringWithFormat:FORMAT, ##__VA_ARGS__] UTF8String]);
#else
#define Log(format, ...) NSLog(format, ## __VA_ARGS__)
#endif
网友评论