Json数组传入后台乱码问题解决

中科白癜风公益惠民活动 https://auto.qingdaonews.com/content/2018-06/26/content_20140182.htm
如果项目的编码为GBK的话,就会导致json数据传入后台时接受的为乱码,在这里我分享一下我这次的跳坑经历;项目编码:GBK问题现象:1:Filter中已经过滤了编码设置2:不管在$.ajax({})中是否设置contentType,及如何设置,都会出现乱码解决方案:1.前台组装json数组push时使用encodeURI()进行编码,例如:varrejectAry=newArray();varrejectInfo={schemaNo:$(#hSchemaNo).val(),fundCode:$(#hFundCode).val(),rejectDesc:$(#rejectDesc).val()};rejectAry.push(encodeURI(JSON.stringify(rejectInfo)));2.后台使用URLDecoder.decode(request.getParameter(rejectAry),UTF-8)以utf-8解码,例如JSONArrayrejectInfoArray=null;try{rejectInfoArray=JSONArray.fromObject(URLDecoder.decode(request.getParameter(rejectAry),UTF-8));}catch(UnsupportedEncodingExceptione1){e1.printStackTrace();}ListRejectInforejectInfoList=JSONArray.toList(rejectInfoArray,newRejectInfo(),newJsonConfig());


转载请注明:http://www.aierlanlan.com/rzdk/6951.html

  • 上一篇文章:
  •   
  • 下一篇文章: