Ana*_*hna 7 java rest spring json spring-rest
我正在获取存储在 DB 中的 JSON(JSON 作为字符串存储在 DB 中)并将其添加到控制器中的模型对象中。
@RequestMapping( method = RequestMethod.GET, value = "/all" )
public void getJson(HttpServletRequest httpServletRequest, Model model){
String json = serviceDao.getResponseJson();
System.out.println(json); //Output: {"Response":[{"Id":"1","Name":"GAD"},{"Id":"2","Name":"GBD"}],"Status":"Success"}
model.addAttribute("result",json);
}
Run Code Online (Sandbox Code Playgroud)
但是当我从浏览器调用服务时,响应中添加了转义字符。
http://localhost:8080/MyApplication/all.json
{"result":"{\"Response\":[{\"Id\":\"1\",\"Name\":\"GAD\"},{\"Id\":\"2 \",\"名称\":\"GBD\"}],\"状态\":\"成功\"}"}
您能否帮助我在没有转义字符的情况下将 JSON 对象发送到 Web 服务中的客户端。
小智 4
不是将字符串添加到模型直接返回 JSON
@RequestMapping(value="/all")
public @ResponseBody String getJson(){
//Logic
return json;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
15466 次 |
| 最近记录: |