1
我有Spring控制器方法,它使用Google.Gson返回json字符串。问题是,我的json字符串有UTF-8内容,当我从浏览器访问url时,它显示编码格式的数据。json的UTF 8解码问题(使用谷歌gson)字符串
@ResponseBody
@RequestMapping(value="/getLocations.json", method = RequestMethod.GET)
public String getLocations(HttpServletRequest request,HttpServletResponse response)throws Exception {
Gson gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().serializeNulls().create();
response.setContentType("application/json; charset=utf-8");
Set<Locations> locs = channelService.getLocations();
String json = gson.toJson(locs);
return json;
}
当我从下面的浏览器地址栏访问getLocations.json是我所得到的:
[{"id":1,"name":"\u0026#3248;\u0026#3262;\u0026#3255;\u0026#3277;\u0026#3231;\u0026#3277;\u0026#3248;\u0026#3264;\u0026#3247;"},{"id":2,"name":"Districts"}]
任何想法,我会拨错?或者我怎样才能解码数据?
尝试删除'字符集= UTF-8' – 2014-08-31 15:22:35
@ ANKUR - 辛格尔,它仍然是相同的 – Praveen 2014-09-01 01:15:30