标签:
public static void test1(){
Person person = new Person();
person.setName("zs");
person.setAge(20);
JSONObject json = JSONObject.fromObject(person);
String str = json.toString();
System.out.println(str);
}
public static void test2(){
Person person1 = new Person();
person1.setName("zs");
person1.setAge(20);
Person person2 = new Person();
person2.setName("ls");
person2.setAge(24);
List<Person> lp = new ArrayList<Person>();
lp.add(person1);
lp.add(person2);
JSONArray json = JSONArray.fromObject(lp);
String str=json.toString();
System.out.println(str);
}
JSON JSONObject.fromObject JSONArray.fromObject
标签:
原文地址:http://www.cnblogs.com/hzzhero/p/4821286.html