private static final Pattern UNICODE_2_STRING_PATTERN = Pattern.compile("(\\\\u(\\p{XDigit}{4}))"); public static String unicode2String(String str) { Matcher matcher = UNICODE_2_STRING_PATTERN.matcher(str); while (matcher.find()) { char ch = (char) Integer.parseInt(matcher.group(2), 16); str = str.replace(matcher.group(1), ch + ""); } return str; }
結果:上線之後發現cpu狂飆100%,一番查找,新加的代碼只有這裏有while會致使cpu太高。java
org.apache.commons.lang3.StringEscapeUtils#unescapeJava