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;
            }

  • 相关阅读:
    最短路总结
    关于最小生成树(并查集)prime和kruskal
    关于优先队列浅析(priority_queue)
    惨痛第十届蓝桥杯总结(附录蓝桥省赛知识点总结)-C++ B组
    初识STL vector
    sort();对结构体数组的排序
    Git 分支管理
    Git 远程仓库
    Matlab R2016a 破解教程
    Ubuntu卡在logo界面
  • 原文地址:https://www.cnblogs.com/xiaowenzi/p/6857738.html
Copyright © 2011-2022 走看看