zoukankan      html  css  js  c++  java
  • json传输数据解决中文乱码问题

    1.Ajax在url带参数(中文):

       encodeURI(encodeURI(expireDesc))//设置编码

    2.后台接收需要转码:

      URLDecoder.decode(expireDesc, "UTF-8") //将接收的参数转码

    3.例子:
    js Ajax:

    function exchange(expireDesc){
                $.ajax({
                 type: "post",  
                 url:ctx+"/xxx.do?method=xxx&xxx="+  encodeURI(encodeURI(xxx)),
                 dataType: "json",
                 success: function(data){
                     xxxx=data.code;
                 }
                })
                
            }

    后台接收:

    public JsonResult exchange(HttpServletRequest request,String expireDesc) {
                    String expire="";
                    try {
                         xxx = URLDecoder.decode(xxx, "UTF-8");//将接收的参数转码,用于解决中文乱码
                    } catch (UnsupportedEncodingException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                MngCodeEntity list = produceService.exchange(expire);
                JsonResult jsonResult = new JsonResult();
                jsonResult.setCode(list.getCodeVal());
                return jsonResult;
            }

  • 相关阅读:
    vue中element-ui的内置过渡动画
    vue路由自动加载、按组件异步载入vuex以及dll优化
    h5春节小游戏制作
    python脚本通过adb命令安装包
    pipeline
    python闭包与装饰器
    linux-awk
    CSAPP Lab3: The Attack Lab
    CSAPP Lab4 Cache Lab
    HDU. 2243. 考研路茫茫——单词情结(AC自动机 DP 矩阵快速幂)
  • 原文地址:https://www.cnblogs.com/xiaowenzi/p/6857738.html
Copyright © 2011-2022 走看看