unicode转中文

支付对接过程中,有些第三方返回给我们的数据是Unicode编码的 ,需要以下操作方能解析
 /**
     * unicode转中文
     */
    public static String unicodeToString(String str) {

        Pattern pattern = Pattern.compile("(\\\\u(\\p{XDigit}{4}))");
        Matcher matcher = pattern.matcher(str);
        char ch;
        while (matcher.find()) {
            ch = (char) Integer.parseInt(matcher.group(2), 16);
            str = str.replace(matcher.group(1), ch+"" );
        }
        return str;
    }
   /* public static void main(String[] args) {
    	System.err.println(unicodeToString("\\u5e94\\u7528\\u672a\\u5173\\u8054\\u652f\\u4ed8\\u901a\\u9053"));
	}*/

猜你喜欢

转载自blog.csdn.net/qq_34567887/article/details/80844903
今日推荐