zoukankan      html  css  js  c++  java
  • JSON数据的中文乱码问题

    问题描述:
    在firefox中返回的JSON数据没有出现乱码,但在GridPanel中显示乱码,而jsp页面和xml文件都是utf-8类型。

    解决方案:

    在 PrintWriter out = response.getWriter(); 语句前使用

    response.setContentType("text/json; charset=utf-8");

    response.setCharacterEncoding("utf-8"); 

    添加后代码如下:

    XXXAction.java :

    String json = "{totalProperty:" + this.getTotalProperty() + ", start:"
    				+ this.getStart() + ", limit:" + this.getLimit() + ", root:"
    				+ listStudent.toString() + "}";
    this.getResponse().setContentType("text/json; charset=utf-8");
    this.getResponse().setCharacterEncoding("utf-8"); 
    super.outPrint(json);     
    System.out.println(json);  // 打印出来看看效果
    super.setContentType(BaseAction.JSON);
    
  • 相关阅读:
    Adb 命令
    python 属性
    python 计时器
    【网易云课堂工作】什么是本能三元组
    functiontools.partial
    源码
    听总结
    线程和死锁
    加入kendall进入计算
    添加K-CORE值进入运算
  • 原文地址:https://www.cnblogs.com/xingmeng/p/3287111.html
Copyright © 2011-2022 走看看