iOS-NSString值为Unicode格式(字符串编码转换成中文编码)

  • + (NSString *)replaceUnicode:(NSString *)unicodeStr 
    {  
          
       NSString *tempStr1 = [unicodeStrstringByReplacingOccurrencesOfString:@"\\u"withString:@"\\U"];  
       NSString *tempStr2 = [tempStr1stringByReplacingOccurrencesOfString:@"\""withString:@"\\\""];  
       NSString *tempStr3 = [[@"\""stringByAppendingString:tempStr2] stringByAppendingString:@"\""];  
       NSData *tempData = [tempStr3dataUsingEncoding:NSUTF8StringEncoding];  
       NSString* returnStr = [NSPropertyListSerializationpropertyListFromData:tempData  
                                                              mutabilityOption:NSPropertyListImmutable   
                                                                        format:NULL  
                                                              errorDescription:NULL];  
        NSLog(@"%@",returnStr);
       return [returnStrstringByReplacingOccurrencesOfString:@"\\r\\n"withString:@"\n"];  
    }
posted @ 2015-12-29 16:06  灵笑若然  阅读(2656)  评论(0编辑  收藏  举报