本文为博主原创,未经允许不得转载:

原本返回json格式数据的代码:

@ResponseBody
@RequestMapping(value = "getListByTime", method = { RequestMethod.POST, RequestMethod.GET })
public String getListByTime(@RequestParam String aoData,String sEcho,HttpServletRequest request) throws Exception { AoData paramAoData = new AoData(aoData); Detail cameraDetail = new Detail ();
detail.setDisplatStart(paramAoData.getiDisplayStart());
detail.setDisplayLength(paramAoData.getiDisplayLength());
List<Detail> list = dataService.getListByTime(detail);
int size = list.size();
String[][] data = new String[size][];
for (int i = ; i < size; i++) {
Detail info = list.get(i);
data[i] = info.values(); }
int total = dataService.getCameraByTimeTotal(detail); return JSonUtils.toJSon(new DataTableReturnObject(total, total, sEcho, data));
}

以上代码断点从数据库中查询的数据没有乱码,但在前台接收的时候乱码。

解决方法:

    @ResponseBody
@RequestMapping(value = "getListByTime", method = { RequestMethod.POST, RequestMethod.GET })
public void getListByTime(@RequestParam String aoData,String sEcho,HttpServletRequest request) throws Exception { AoData paramAoData = new AoData(aoData); Detail cameraDetail = new Detail ();
detail.setDisplatStart(paramAoData.getiDisplayStart());
detail.setDisplayLength(paramAoData.getiDisplayLength());
List<Detail> list = dataService.getListByTime(detail);
int size = list.size();
String[][] data = new String[size][];
for (int i = ; i < size; i++) {
Detail info = list.get(i);
data[i] = info.values(); }
int total = dataService.getCameraByTimeTotal(detail); PrintWriter out = null;
try
{
String result = JSonUtils.toJSon();
out = response.getWriter();
out.print(result);
out.flush();
}
catch (Exception e) {
LOG.error("error",e);
}
finally
{
if (out != null) {
out.close();
}
}
}

解决方案为:将对象通过流的形式进行传输给前台,PrintWriter向文本输出流打印对象的格式化表示形式。

返回json格式数据乱码的更多相关文章

  1. 使用jQuery发送POST,Ajax请求返回JSON格式数据

    问题: 使用jQuery POST提交数据到PHP文件, PHP返回的json_encode后的数组数据,但jQuery接收到的数据不能解析为JSON对象,而是字符串{"code" ...

  2. Spring MVC 学习笔记11 —— 后端返回json格式数据

    Spring MVC 学习笔记11 -- 后端返回json格式数据 我们常常听说json数据,首先,什么是json数据,总结起来,有以下几点: 1. JSON的全称是"JavaScript ...

  3. WebService返回json格式数据供苹果或者安卓程序调用

    1.新建一个WebService. 2. /// <summary> /// DemoToJson 的摘要说明 /// </summary> [WebService(Names ...

  4. Django 1.8.11 查询数据库返回JSON格式数据

    Django 1.8.11 查询数据库返回JSON格式数据 和前端交互全部使用JSON,如何将数据库查询结果转换成JSON格式 环境 Win10 Python2.7 Django 1.8.11 返回多 ...

  5. ajax请求后台,返回json格式数据,模板!

    添加一个用户的时候,需要找出公司下所有的部门,和相应部门下的角色,利用ajax请求,实现联动技术.将返回的json格式数据,添加到select标签下. <script type="te ...

  6. 如何让webapi只返回json格式数据

    最近脑子不好用,总记不住事,以前搞过让webapi只返回json格式的数据,今天有人问我又突然想不起了,后来总结一下,备忘一下,大概有下面几种处理方式 1.在WebApiConfig类的Registe ...

  7. springmvc通过ajax异步请求返回json格式数据

    jsp 首先创建index.jsp页面 <script type="text/javascript"> $(function () { $("#usernam ...

  8. C#返回JSON格式数据

    又类的属性生成json格式数据 using System; using System.Collections.Generic; using System.Linq; using System.Web; ...

  9. ajax提交数据到java后台,并且返回json格式数据前台接收处理值

    1.前台html页面.有一段代码如下: 账  户:  <input type="text" name="userName" id="userN& ...

随机推荐

  1. 去掉UITableView多余的分割线

    UIView *v = [[UIView alloc] initWithFrame:CGRectZero]; [_tableView setTableFooterView:v];

  2. ubuntu 下执行定时任务

    Window shell文件在linux系统下执行不了的解决办法 一些人喜欢用vim来写linux shell script, 但是, 有的人喜欢在Windows下用一些方便的编辑器(比如鼎鼎大名的N ...

  3. 让人抓狂的MySQL安装-8.0.12版本

    今天一个下午就做了一件事,把MySQL安装成功,安装的过程让人很狂躁.于是一边骂,一边查错,才把这个软件给安装成功了. 详细的安装步骤,这里就不赘述了.参见https://blog.csdn.net/ ...

  4. spring boot配置service发布服务

    在application.yml中配置 server: port: 8080 context-path: /crm spring: datasource: driver-class-name: com ...

  5. 十四、springboot全局处理异常(@ControllerAdvice + @ExceptionHandler)

    1.@ControllerAdvice 1.场景一 在构建RestFul的今天,我们一般会限定好返回数据的格式比如: { "code": 0, "data": ...

  6. (转)HTML5开发中Access-Control-Allow-Origin跨域问题

    今天准备通过JavaScript的方式调用问说问答的内容,由于使用的不同的二级域名,遇到了一个跨域问题,虽然可以使用JSON或者XML来解决这个问题,但是我们可以通过Access-Control-Al ...

  7. eclipse向svn提交代码的时候忽略部分资源配置

    eclipse向svn提交代码的时候有 .settings, .project, .classpath, target等不需要上传,所以在eclipse中配置一下就不会显示了,方法如下图:

  8. openstack 部署笔记--dashboard

    控制节点 # yum install openstack-dashboard # vim /etc/openstack-dashboard/local_settings OPENSTACK_HOST ...

  9. python -- 解决If using all scalar values, you must pass an index问题

    [问题描述] 在将dict转为DataFrame时会报错:If using all scalar values, you must pass an index 例如: summary = pd.Dat ...

  10. jmeter bean shell断言加密的响应信息(加密接口测试二)

    断言加密的响应信息 1.在http请求-->添加-->断言-->bean shell 断言 import com.changfu.EncryptAndDecryptInterface ...