返回 xml格式:
<?xml version='1.0' encoding='utf-8' ?><categorylist><category id="1308" name="1234567890123456789012345678901234567890"
/><category id="1292" name="11@#¥%……&*()——+|!QWERTY2111111122222211"/><category id="1287" name="11@#
¥%……&*()——+|!QWERTY21111112222222"/><category id="1282" name="10.1234567890"/><category id="1281" name
="9"/><category id="1280" name="8"/><category id="1279" name="5"/><category id="1278" name="7"/><category
id="1277" name="6"/><category id="1276" name="4"/></categorylist>
1. 接口返回之前编码
String c1="中国11@#¥%……&*()——+|!QWERTY2111111122222211中国";
String a211;
try {
a211 = java.net.URLEncoder.encode(c1,"UTF-8");
System.out.println("encode=="+a211);
} catch (UnsupportedEncodingException e1) {
// TODO 自动生成 catch 块
e1.printStackTrace();
}
编码后:
%E4%B8%AD%E5%9B%BD11%40%23%EF%BF%A5%25%E2%80%A6%E2%80%A6%26*%EF%BC%88%EF%BC%89%E2%80%94%E2%80%94%2B%7C%EF%BC%81QWERTY2111111122222211%E4%B8%AD%E5%9B%BD
2. 返回时js脚本解析时解码:
<script>
var a="%E4%B8%AD%E5%9B%BD11%40%23%EF%BF%A5%25%E2%80%A6%E2%80%A6%26*%EF%BC%88%EF%BC%89%E2%80%94%E2%80%94%2B%7C%EF%BC%81QWERTY2111111122222211%E4%B8%AD%E5%9B%BD";
alert(decodeURIComponent(a));
</script>