字典打印中文的问题

首先想到的方法是在description方法中重新遍历修改, 这里推荐字符串处理Unicode编码的方式.

首先还是在字典分类中覆盖原先的description方法, 这里的unicodeString方法是下一步需要实现的NSString分类对象方法

- (NSString *)descriptionWithLocale:(id)locale {
    return self.description.unicodeString;
}

在NSString分类中实现字符串处理Unicode编码

- (NSString *)unicodeString {
//    return @"kkkllpp";
    
    NSString *tempStr1 = [self stringByReplacingOccurrencesOfString:@"\\u" withString:@"\\U"];
    
    
    
    NSString *tempStr2 = [tempStr1 stringByReplacingOccurrencesOfString:@"\"" withString:@"\\\""];
    
    NSString *tempStr3 = [[@"\"" stringByAppendingString:tempStr2] stringByAppendingString:@"\""];

    
    NSData *tempData = [tempStr3 dataUsingEncoding:NSUTF8StringEncoding];
    
    NSPropertyListFormat format = NSPropertyListOpenStepFormat;
    
    
    /* Create a property list from an NSData. The options can be any of NSPropertyListMutabilityOptions. If the format parameter is non-NULL, it will be filled out with the format that the property list was stored in. If an error occurs the return value will be nil and the error parameter (if non-NULL) set to an autoreleased NSError describing the problem.
     */
    return [NSPropertyListSerialization propertyListWithData:tempData options:NSPropertyListImmutable format:&format error:nil];
    
//    return [returnStr stringByReplacingOccurrencesOfString:@"\\r\\n" withString:@"\n"];
}

最后用到的属性列表序列化函数, 没有大神指点很难想到

参考: https://www.jianshu.com/p/040293327e18

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • OC中的类分为可变和不可变。下表列出了Foundation框架中主要的可变类和不可变类: 种类 不可变类 可变类 ...
    陈_振阅读 566评论 0 0
  • 在当前这个时代(比如说公元2016年),如果你并不是在维护历史遗留的文本处理代码,没有在每个地方都使用Unicod...
    纵横而乐阅读 2,781评论 3 16
  • 图片发自简书App 放下电话,言夏就往燕习街跑。跑到街拐角处,言夏看到了正站在车旁边的路遥,他正和洗车的人说着什么...
    惨绿青年n阅读 214评论 0 0
  • 准确性练习 1.China and Russia vetoed a U.N. resolution on Febr...
    Yo_Tenko阅读 162评论 0 0
  • 苦难,你是什么呢。 今天想说说我的一个室友t,突然说起她是因为又看到她在接完一个电话后哭了。很心疼这样的她。 打电...
    简小取阅读 480评论 20 2