解决前:
ok前.jpg解决后:
解决后.png注意:看第一张图片,我取出数组里的元素和字典里的值的时候,是可以正常输出汉字的.所以解决方案来了,遍历数组里的元素和字典的键值对就可以解决.但是,请不要麻烦写for循环了.写个分类category.
看左边蓝色选中的文件:
//
// NSArray+EX.m
// 解决数组字典输出汉字的问题
//
// Created by Mac on 2017/8/28.
// Copyright © 2017年 Mac. All rights reserved.
//
#import "NSArray+EX.h"
@implementation NSArray (EX)
- (NSString *)descriptionWithLocale:(id)locale{
NSMutableString * mStr = [NSMutableString string];
[mStr appendString:@"(\r\n"];
[self enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
[mStr appendFormat:@"\t%@,\r\n",obj];
}];
[mStr appendString:@")"];
return mStr.copy;
}
@end
//
// NSDictionary+EX.m
// 解决数组字典输出汉字的问题
//
// Created by Mac on 2017/8/28.
// Copyright © 2017年 Mac. All rights reserved.
//
#import "NSDictionary+EX.h"
@implementation NSDictionary (EX)
- (NSString *)descriptionWithLocale:(id)locale
{
NSMutableString *string = [NSMutableString string];
// 开头有个{
[string appendString:@"{\n"];
// 遍历所有的键值对
[self enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) {
[string appendFormat:@"\t%@", key];
[string appendString:@" : "];
[string appendFormat:@"%@,\n", obj];
}];
// 结尾有个}
[string appendString:@"}"];
// 查找最后一个逗号
NSRange range = [string rangeOfString:@"," options:NSBackwardsSearch];
if (range.location != NSNotFound)
[string deleteCharactersInRange:range];
return string;
}
@end
把写好的文件拖到你的项目里就OK了。
网友评论