//java bean的三大条件:1.私有化的属性 2.公共的get/set方法 3.一个无参构造器
//1.将javaBean对象转换成json格式的字符串
User user = new User("zhangsan",20);
String useStr = JSON.toJSONString(user);
System.out.println(useStr);
//2.将 json格式的字符串转换成javaBean对象
String jsonStr = "{ \"name\" : \"lisi\",\"age\" : 25 }";
User user01 = JSON.parSEObject(jsonStr,User.class);
System.out.println(user01.getName());
System.out.println(user01.getAge());
//3.将 json格式的字符串(数组)转换成java中的List
String userList = "[{ \"name\" : \"wangwu\",\"age\" : 23 },{ \"name\" : \"zhaoliu\",\"age\" : 20 }]";
List<User> list = JSON.parseArray(userList,User.class);
System.out.println(list.size());
System.out.println(list.get(1).getName());
System.out.println(list.get(0).getAge());
//4.将List转化为json格式的字符串
List<User> list2 = new ArrayList();
list2.add(new User("qianyi",26));
list2.add(new User("suner",23));
list2.add(new User("zhangsan",25));
list2.add(new User("lisi",24));
String str2 = JSON.toJSONString(list2);
System.out.println(str2);