使用JSONObject需要引用org.json包
response.setCharacterEncoding("UTF-8");
response.setContentType("application/json; charset=utf-8");
PrintWriter out =null;
try{
JSONObject res =newJSONObject();
res.put("success","true");
res.put("msg",hostHolder.getUser());
out = response.getWriter();
out.append(res.toString());
}
catch(Exception e){
e.printStackTrace();
response.sendError(500);
}
网友评论