使用jQuery ajax调用的返回json,中文乱码问题
Jquery :
- $.ajax({
- url: '/test/testAction.do?method=test',
- type: 'POST',
- dataType: 'json',
- timeout: 5000,
- async: false,
- error: function(){
- alert('获取数据失败!');
- },
- success: function(json){
- jsObject = eval(json);
- }
- });
- return jsObject;
- <span style="font-size: x-small;">$.ajax({
- url: '/test/testAction.do?method=test',
- type: 'POST',
- dataType: 'json',
- timeout: 5000,
- async: false,
- error: function(){
- alert('获取数据失败!');
- },
- success: function(json){
- jsObject = eval(json);
- }
- });
- return jsObject;</span>
action:
- JSONArray json = JSONArray.fromObject(SysList);//SysList是一个List
- // 设置response的ContentType解决中文乱码
- response.setContentType("text/html;charset=UTF-8");
- response.getWriter().print(json.toString());
- return null;
- <span style="font-size: x-small;">JSONArray json = JSONArray.fromObject(SysList);//SysList是一个List
- // 设置response的ContentType解决中文乱码
- response.setContentType("text/html;charset=UTF-8");
- response.getWriter().print(json.toString());
- return null;</span>