SpringMVC Controller后台返回Json到前台乱码问题
2018-03-28 10:07
453 查看
乱码问题主要是字符编码的问题
可通过指定字符格式来解决,不多说,直接上图
@RequestMapping(value = { "json" } ,produces = "application/json; charset=utf-8")
@ResponseBody
public String json(Operation operation,Model model,HttpServletRequest request,HttpServletResponse response) {
JSONObject outobj=new JSONObject();
JSONArray contentManagement =new JSONArray();
JSONObject innerobj = new JSONObject();
innerobj.put("title", "文章列表");
innerobj.put("icon", "icon-text");
innerobj.put("href", "page/news/newsList.html");
innerobj.put("spread", false);
contentManagement.put(innerobj);
outobj.put("contentManagement", contentManagement);
return outobj.toString();
}
前台显示不是json数据格式的话有两种解决办法
1、后台直接指定返回数据的格式为json,如上代码
2、前台使用Json.parse(data)来进行格式转换
可通过指定字符格式来解决,不多说,直接上图
@RequestMapping(value = { "json" } ,produces = "application/json; charset=utf-8")
@ResponseBody
public String json(Operation operation,Model model,HttpServletRequest request,HttpServletResponse response) {
JSONObject outobj=new JSONObject();
JSONArray contentManagement =new JSONArray();
JSONObject innerobj = new JSONObject();
innerobj.put("title", "文章列表");
innerobj.put("icon", "icon-text");
innerobj.put("href", "page/news/newsList.html");
innerobj.put("spread", false);
contentManagement.put(innerobj);
outobj.put("contentManagement", contentManagement);
return outobj.toString();
}
前台显示不是json数据格式的话有两种解决办法
1、后台直接指定返回数据的格式为json,如上代码
2、前台使用Json.parse(data)来进行格式转换
相关文章推荐
- SpringMvc从后台返回到前台的json数据出现了乱码的问题
- spring boot 解决后台返回 json 到前台出现中文乱码的问题
- SpringMVC使用@RequestBody后台返回前台中文字符串乱码的问题解决方案
- SSM框架:解决后台传数据到前台中文乱码问题,使用@ResponseBody返回json 中文乱码
- SpringMVC3.2 处理Ajax请求时返回json字符串的中文乱码问题
- 处理SpringMVC返回json乱码问题
- SpringMVC的@ResponseBody返回JSON,中文乱码问题的解决.
- springMvc框架解决返回Json格式中文乱码问题
- java中后台返回前台数据中文乱码的问题
- SpringMVC使用注解@ResponseBody返回json以及中文乱码问题解决
- spring boot 解决后台返回 json 到前台中文乱码之后出现返回json数据报错 500
- SpringMVC返回JSON乱码问题解决办法
- Ajax前台返回JSON数据后再Controller中直接转换成类型使用,后台接收json转成实体的方法
- SpringMVC 3.1下返回json时中文显示乱码问题的解决方案
- 解决SpringMvc后台接收json数据中文乱码问题
- Struts2中的JSON问题——后台返回JSON字符串到前台
- SpringMVC3的ResponseBody返回字符串(JSON)乱码问题解决
- 解决SpringMvc后台接收json数据中文乱码问题
- Spring MVC后台返回JSON数据中文乱码问题解决