标签:有效期 port 方法 编写 com mat static param ace
问题:有时我们用utf-8去接收,结果接收到的是unicode码,这时就需要将unicode转成string
列如:
<MSG>\r\n<RES>\r\n<RES.1>2020-07-12 10:34:31<\/RES.1>\r\n<RES.2>0<\/RES.2>\r\n<ERR Code=\"00000.01\">\u672A\u67E5\u8BE2\u5230\u6302\u53F7\u4FE1\u606F\u6216\u6302\u53F7\u4FE1\u606F\u5DF1\u8D85\u8FC7\u6709\u6548\u671F!<\/ERR>\r\n<\/RES>\r\n<\/MSG>
解决:编写一个方法将unicode码转成utf-8码
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* unicode转成string
* @param str
* @return
*/
public static String unicodeToString(String str) {
Pattern pattern = Pattern.compile("(\\\\u(\\p{XDigit}{4}))");
Matcher matcher = pattern.matcher(str);
char ch;
while (matcher.find()) {
//group 6728
String group = matcher.group(2);
//ch:‘木‘ 26408
ch = (char) Integer.parseInt(group, 16);
//group1 \u6728
String group1 = matcher.group(1);
str = str.replace(group1, ch + "");
}
return str;
}
转换结果:
<MSG><RES><RES.1>2020-07-12 10:34:31</RES.1><RES.2>0</RES.2><ERR Code="00000.01">未查询到挂号信息或挂号信息己超过有效期!</ERR></RES></MSG>
标签:有效期 port 方法 编写 com mat static param ace
原文地址:https://www.cnblogs.com/xiaofengshan/p/13287369.html