iOS Unicode转汉字
2018-02-06 本文已影响21人
Auditore
// 例如unicode转汉字例如服务器给我们的原始字符串为\\u6b63\\u5728\\u52a0\\u70ed\\uff0c\\u5f53\\u524d\\u6e29\\u5ea6\\uff1a30.0\\u2103
需要转为中文该怎么办呢?\号后面加个字符就会被转译成其他字符, 如下为解决方案
- (NSString*) replaceUnicode:(NSString*)TransformUnicodeString
{
NSString *tepStr1 = [TransformUnicodeString stringByReplacingOccurrencesOfString:@"\\u"withString:@"\\U"];
NSString *tepStr2 = [tepStr1 stringByReplacingOccurrencesOfString:@"\""withString:@"\\\""];
NSString *tepStr3 = [[@"\"" stringByAppendingString:tepStr2]stringByAppendingString:@"\""];
NSData *tepData = [tepStr3 dataUsingEncoding:NSUTF8StringEncoding];
NSString *axiba = [NSPropertyListSerialization propertyListWithData:tepDataoptions:NSPropertyListMutableContainers
format:NULLerror:NULL];
return [axiba stringByReplacingOccurrencesOfString:@"\\r\\n"withString:@"\n"];
}