每次不知道的问题就是百度,不知看的那篇文章找到了以下代码。
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过高。
总结:网上查找的东东,且用且珍惜!!!
发现commons包中有个转码工具类
org.apache.commons.lang3.StringEscapeUtils#unescapeJava