java 中文字符和unicode编码值相互转化

java 中文字符和unicode编码值相互转化

https://blog.csdn.net/u011366045/article/details/79235217

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u011366045/article/details/79235217
1、引用工具 import com.alibaba.fastjson.JSON;

2、转化方法

    //unicode转中文
    public static String unicodeToString(String str) {  
        return String.valueOf(JSON.parse(str));
    }
    
    //中文字符转unicode
    public static String stringToUnicode(String s) {  
        return JSON.toJSONString(s, SerializerFeature.BrowserCompatible);
        
    }

3、转化效果

你好 -->"u4F60u597D" -->你好

附:在使用方法“unicodeToString”,对象中如果有字符,必须有双引号,eg: String str = ""你好"";
---------------------
作者:智强风
来源:CSDN
原文:https://blog.csdn.net/u011366045/article/details/79235217
版权声明:本文为博主原创文章,转载请附上博文链接!

原文地址:https://www.cnblogs.com/handsome1013/p/11284356.html