ios html转码json,iOS返回的JSON数据中的unicode 转换为中文

参考ZXPUnicode。数组

核心代码为:函数

1.给NSObject添加一个分类:spa

+(NSString *)stringByReplaceUnicode:(NSString *)string{code

NSMutableString *convertedString = [string mutableCopy];orm

[convertedString replaceOccurrencesOfString:@"\\U" withString:@"\\u" options:0 range:NSMakeRange(0,convertedString.length)];ip

CFStringRef transform = CFSTR(Any-Hex/Java);get

CFStringTransform( (__bridge CFMutableStringRef)convertedString),NULL,transform,YES);string

return convertedString;it

}io

2.给数组添加一个分类:

引入头文件 #import

注意这里用到了运行时里的method_exchangeImplementations()方法

补充说明:load函数是只要你动态加载或者静态引用了这个类,那么load就会被执行,它并不须要你显示的去建立一   个类后才会执行,同时只执行一次。 关于load的执行顺序问题,全部的superclass的load执行完之后才会执行该类的load。而且class中的load方法是先于category中的load执行的。

+(void)load{

method_exchangeImplementations(class_getInstanceMethod([self class],@selector(description)),                        class_getInstanceMethod([self class],@selector(replaceDescription)));//交换系统的description添加新实现

method_exchangeImplementations(class_getInstanceMethod([self class],@selector(descriptionWithLocale:)),                        class_getInstanceMethod([self class],@selector(replaceDescriptionWithLocale:)));

}

- (NSString *)replaceDescription{

return [NSObject stringByReplaceUnicode :[self replaceDescription]];    //[selfreplaceDescription] 调用的是系统的description

}

-  (NSString *) replaceDescriptionWithLocale:(nullable id)locale{

return [NSObject stringByReplaceUnicode:[self replaceDescriptionWithLocal:local]];

}

3.给字典添加一个分类,和数组分类相似,这里就不写了。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值