乱码问题主要是字符编码的问题
可通过指定字符格式来解决,不多说,直接上图
@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)来进行格式转换