客户端如何获取以上JSON格式数据:
服务端代码如下
ArrayList arr = new ArrayList();
List<User> list = userDao.getUser();
for (User user : list) {String s = "{";s += "\"id\":" + user.getId() + ",";s += "\"name\":" + "\"" + user.getName() + "\"" + ",";s += "\"username\":" + "\"" + user.getPassword() + "\"" + ",";s += "\"password\":" + "\"" + user.getPassword() + "\"" ;s += "}";System.out.println(s);arr.add(s);}
resp.getWriter().print(arr);
注意:其中List<User> list = userDao.getUser();是返回查询表中所有信息,获取的信息如下图所示
客户端处理服务端发来的响应,代码如下
客户端处理处理结果