您的位置:首页 > 其它

关于ajax $.post() 返回乱码问题

2011-11-11 11:15 225 查看
一直出现乱码,关键在这里,请看这两段代码的区别

Gson gson = new Gson();
String str = gson.toJson(users);

response.setContentType("application/json; charset=utf-8");
response.setHeader("pragma", "no-cache");
response.setHeader("cache-control", "no-cache");
PrintWriter out = response.getWriter();

out.println(str);
out.flush();


Gson gson = new Gson();
String str = gson.toJson(users);
PrintWriter out = response.getWriter();
response.setContentType("application/json; charset=utf-8");
response.setHeader("pragma", "no-cache");
response.setHeader("cache-control", "no-cache");
out.println(str);
out.flush();


response.setContentType("application/json; charset=utf-8");//前者没有乱码,后者有乱码,关键在于这句话的位置
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: