解决IOS 中文unicode编码问题

//unicode编码以\u开头

+ (NSString *)replaceUnicode:(NSString *)unicodeStr

{

    

    NSString *tempStr1 = [unicodeStr stringByReplacingOccurrencesOfString:@"\\u"withString:@"\\U"];

    NSString *tempStr2 = [tempStr1 stringByReplacingOccurrencesOfString:@"\""withString:@"\\\""];

    NSString *tempStr3 = [[@"\""stringByAppendingString:tempStr2] stringByAppendingString:@"\""];

    NSData *tempData = [tempStr3 dataUsingEncoding:NSUTF8StringEncoding];

    NSString* returnStr = [NSPropertyListSerialization propertyListFromData:tempData

                                                          mutabilityOption:NSPropertyListImmutable

                                                                    format:NULL

                                                          errorDescription:NULL];

    return [returnStr stringByReplacingOccurrencesOfString:@"\\r\\n"withString:@"\n"];

}

以上代码最好改成宏定义,直接放在Log中。

你可能感兴趣的:(unicode)