public static String getURLEncoderString(String str) {
String result = "";
if (null == str) {
return "";
}
try {
result = java.net.URLEncoder.encode(str, "UTF-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
return result;
}
public static String URLDecoderString(String str) {
String result = "";
if (null == str) {
return "";
}
try {
result = java.net.URLDecoder.decode(str, "UTF-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
return result;
}
替换url 中的 = 和 &
String urlEncoderString = getURLEncoderString("data={\"version\":5,\"orderPayType\":\"13\",\"amount\":10,\"invoiceType\":0,\"terminalVersion\":\"WAP|06\",\"addressNo\":\"1\",\"consignee\":\"张三\",\"phonenum\":\"157****6315\",\"address\":\"快递自取\",\"zipCode\":\"\",\"cityCode\":\"370\",\"provinceId\":\"180\",\"provinceName\":\"河南省\",\"cityId\":\"370\",\"districtId\":\"02\",\"townId\":\"99\",\"deliveryAddrMain\":\"河南省商丘市睢阳区全区|快递自取\",\"deliveryArea\":\"3700299\",\"invoiceTitle\":\"张三\",\"customerMsg\":\"\"}&provinceName=河南省&cityName=商丘市&districtName=睢阳区&townName=全区&detailedAddress=快递自取&couponNos=&cardNumbers=&detect="+detect);
String s = urlEncoderString.replaceAll("%3D", "=").replaceAll("%26","&");
System.out.println(s);