iOSiOS点滴iOS 开发

iOS解决NSArray、NSDictionary打印乱码问题

2015-08-08  本文已影响2733人  icoder

原来打印

dict = {
key1 = abc;
key2 = "\U4e2d\U6587";
} 

array = (
abc,
"\U4e2d\U6587"
)

使用方法:将 NSArray+Extension 和 NSDictionary+Extension 两个分类拖入项目即可

打印效果 :

2015-08-08 10:19:36.294 ICUnicodeDemo[2135:50801]

dict = {
key1 = abc,
key2 = 中文
} 


array = [
abc,
中文
]

代码git:https://github.com/icoder20150719/ICUnicodeDemo

解释

0D0F13E7-9592-4B53-A838-120180E7EF5C.png B20B2D00-D229-4962-9C3D-7E171C87E202.png

字典和数组中都出现了Unicode编码字符串问题 ,无法显示出中文

思考字典和数组在打印的过程中分别会调哪些方法:
1、重写系统数组的几个返回字符串的方法

EC3D8956-0F51-4004-B1F5-36F0BCAA7091.png

2、打上短点

690812A6-9CC7-475F-AF10-6AA017E86C3F.png

断点停在 -(NSString *)descriptionWithLocale:(id)locale
过掉断点
3、后台打印: array = descriptionWithLocale

F35D47F7-BA8C-4688-A80A-E06E929C4C7F.png

证明:数组在打印时会调用descriptionWithLocale来把自己格式化成字符串 ;
自定义数组格式化descriptionWithLocale 返回字符串


96647E23-6798-4C38-9877-F36A7F74F59D.png

字典同理:


现在看看后台打印效果:

ECC19C65-7A40-4DBF-A3C4-06B4ADC3C38E.png

代码git:https://github.com/icoder20150719/ICUnicodeDemo


上一篇 下一篇

猜你喜欢

热点阅读