Latest0.0.2
Homepagehttps://github.com/jalyResource/JLLogEncoding
LicenseApache License, Version 2.0
Platformsios 7.0, requires ARC

解决打印字典时,中文乱码问题。

1、 原理

参考文章 iOS 解决打印字典时,中文乱码问题

2、使用方法

1、cocoapods

pod 'JLLogEncoding'

2、手动添加文件

将 JLLogEncoding 目录下的 NSArray NSDictionary 的扩展文件拖进工程即可

pic

3、其它转码方式的缺点

- (NSString *)getUTF8String {
    if ([self isKindOfClass:[NSDictionary class]] == NO) {
        return @"";
    }
    NSError *error = nil;
    NSData *data = [NSJSONSerialization dataWithJSONObject:self options:NSJSONWritingPrettyPrinted error:&error];
    if (error) {
        return @"";
    }
    NSString *str = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
    return str;
}

通过以上方式,将 JSON 转为字符串,虽然可解决中文乱码问题,但当 NSDictionary 中包含普通对象时,无法将对象转成字符串,进而导致程序崩溃。

Latest podspec

{
    "name": "JLLogEncoding",
    "version": "0.0.2",
    "summary": "u89e3u51b3u6253u5370u5b57u5178u65f6uff0cu4e2du6587u4e71u7801u95eeu9898u3002",
    "description": "JLLogEncoding u89e3u51b3u6253u5370u5b57u5178u65f6uff0cu4e2du6587u4e71u7801u95eeu9898u3002",
    "homepage": "https://github.com/jalyResource/JLLogEncoding",
    "license": "Apache License, Version 2.0",
    "authors": "u5434u8d1eu5229",
    "platforms": {
        "ios": "7.0"
    },
    "source": {
        "git": "https://github.com/jalyResource/JLLogEncoding.git",
        "tag": "0.0.2"
    },
    "source_files": "JLLogEncoding-Demo/JLLogEncoding/JLLogEncoding/**/*.{h,m}",
    "requires_arc": true
}

Pin It on Pinterest

Share This