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、轉化效果
你好 -->"\u4F60\u597D" -->你好
附:在使用方法“unicodeToString”,對象中如果有字符,必須有雙引號,eg: String str = "\"你好\"";
---------------------
作者:智強風
來源:CSDN
原文:https://blog.csdn.net/u011366045/article/details/79235217
版權聲明:本文為博主原創文章,轉載請附上博文鏈接!
