servlet怎么返回一个json对象

2025-04-16 07:14:03
推荐回答(1个)
回答1:

response.setContentType("application/json");
response.setCharacterEncoding("UTF-8");
JSONObject json=new JSONObject();
//json给值省略
response.getWriter().println(json.toString());