首先将JSON对象转换为String
。然后将其写入响应编写器以及application/json
UTF-8的内容类型和字符编码。
用到了阿里的fastjson
protected void doXxx(HttpServletRequest request, HttpServletResponse response) { // ... String json = JSON.toJsonString(someObject); response.setContentType("application/json"); response.setCharacterEncoding("UTF-8"); response.getWriter().write(json);}