1.json格式字符串:
String json= "{\"msg\":\"成功\",\"code\":100,\"content\":\"插入3条数据\"}";
2.java对象:
Result result = new Result();
result.put("msg","成功");
result.put("code",100);
result.put("content","插入3条数据");
JsonObject jsonObject = JsonObject.fromObject(result);
response.setCharacterEncoding("utf-8");//响应字符集的编码格式 response.getWriter().print(jsonObject.toString());
3.Map:
Map map=newHashMap();
String json= "{\"msg\":\"成功\",\"code\":100,\"content\":"插入3条数据"}";
map.put("json", json);
returnjsonMap;
网友评论