每次不知道的问题就是百度,不知看的那篇文章找到了以下代码。
1 private static final Pattern UNICODE_2_STRING_PATTERN = Pattern.compile("(\\\\u(\\p{XDigit}{4}))"); 2 3 public static String unicode2String(String str) { 4 Matcher matcher = UNICODE_2_STRING_PATTERN.matcher(str); 5 while (matcher.find()) { 6 char ch = (char) Integer.parseInt(matcher.group(2), 16); 7 str = str.replace(matcher.group(1), ch + ""); 8 } 9 return str; 10 }
结果:上线以后发现cpu狂飙100%,一番查找,新加的代码只有这里有while会导致cpu过高。
总结:网上查找的东东,且用且珍惜!!!
发现commons包中有个转码工具类
org.apache.commons.lang3.StringEscapeUtils#unescapeJava