URLDecoder.decode解析%报错问题

{"errCode":"0000","desc":"\u83b7\u53d6\u6570\u636e\u6210\u529f","data":[{"id":"9837","cid":"39","product_name":"\u7279\u8bfa\u5a1c5%\u6a44\u6984\u690d\u7269\u8c03\u548c\u6cb95L","product_img":"https:\/\/img.li91.com\/2023\/10\/500x500\/n0\/b51d588d6778e4809a4b7d4ea58cbec8.jpg","points_price":"590","price":"188.00","is_rob":1,"supplier_id":"1","real_point":"940","dummy":"0","status":"1","buy_type":"1","is_ax":0,"stock":"100","end_time":"1700063999","begin_time":"1698768000","price_status":0}]}

解决办法:可以替换含有%的字符为%25

java:

String decodeURL = decodeURL.replaceAll("%(?![0-9a-fA-F]{2})", "%25");
String decodeURL = URLDecoder.decode(decodeURL, "UTF-8"); 

讲解下%(?![0-9a-fA-F]{2}):

不匹配%后面两位为数字或字母(包括大小写)的字符;这样就把正确的排除了,其余的是要匹配替换的。

 

Js:

result.fileName.split('%').join(escape('%'))

  

posted @ 2023-11-01 17:23  三七、  阅读(299)  评论(0编辑  收藏  举报