URLDecoder: Illegal hex characters in escape (%) pattern - For input string: "","
问题描述:今天使用post发送json串时发生如上url解析错误,因为pojo中包含了%号。解决方法如下所示。
pojo = pojo.replaceAll("%(?![0-9a-fA-F]{2})", "%25");
/**
* POJO 转 JSON
*/
public static <T> String getJson(T tResponse) throws Exception{
String pojo = JSONObject.toJSONString(tResponse);
pojo = pojo.replaceAll("%(?![0-9a-fA-F]{2})", "%25");
return URLDecoder.decode(pojo, "utf-8");
}