背景:
由于XCode8更新后,第三方插件基本上不能使用。控制台输出的数据是Unicode格式,解决方式很简单,只用建一个NSDictionary的分类,添加一个方法。
在.m文件中添加方法- (NSString *)descriptionWithLocale:(nullable id)locale;
#import "NSDictionary+MZLog.h"
@implementation NSDictionary (MZLog)
#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
现在,你可以用以下代码作为json文件的内容测试一下了。
{
"json" : "MyData",
"status" : "success",
"kind" : {
"food" : "false",
"isFresh" : "ture",
"guess" : "\u4e70\u5bb6\u7248\u672c\u66f4\u65b0",
"instruments" : "1.\u9996\u9875\u5e7f\u544a\u652f\u6301\u4fc3\u9500\u5546\u54c12.\u542f\u52a8\u9875\u589e\u52a0\u5e7f\u544a\u56fe\u7247",
"url" : "www.baidu.com",
"version" : "2.1.3"
}
}
网友评论