JSON串有两种格式:JSONObject、JSONArray,数据格式如下:
JSONObject:{"address":"昌平区","postNum":"100000","name":"志刚"}
JSONArray:[{"address":"西城区","postNum":"100001","name":"张三"}]
/**
*
* JSONObject测试
*
* @return
*/
public void jsonObjectTest(){
List userInfosList = new ArrayList();
UserInfo u1 = new UserInfo();
u1.setUserId(10000);
u1.setUserName("柳");
u1.setPassword("liumengli");
UserInfo u2 = new UserInfo();
u2.setUserId(10001);
u2.setUserName("韩");
u2.setPassword("hanlingsha");
UserInfo u3 = new UserInfo();
u3.setUserId(10002);
u3.setUserName("云");
u3.setPassword("yuntianhe");
UserInfo u4 = new UserInfo();
u4.setUserId(10003);
u4.setUserName("玄");
u4.setPassword("xuanxiao");
userInfosList.add(u1);
userInfosList.add(u2);
userInfosList.add(u3);
userInfosList.add(u4);
Map map=new HashMap();
map.put("newData", userInfosList);
JSONObject jsonObject=JSONObject.fromObject(map);
System.out.println(jsonObject);
}
REF
https://www.jb51.net/article/65855.htm
https://www.cnblogs.com/Yasha/p/6268562.html
https://blog.csdn.net/tjcyjd/article/details/7007487