FastJSON 之bean列表转换为JSON

时间:2022-08-23 05:31:06

实例

import java.util.ArrayList;
import java.util.List; import com.alibaba.fastjson.JSON; public class TestJSON {
public static <T> String serialize(T object) {
return JSON.toJSONString(object);
} public static void main(String[] args) {
Person person1 = new Person();
person1.setAddress("北京市");
person1.setAge(11);
person1.setName("amao"); Person person2 = new Person();
person2.setAddress("河北省");
person2.setAge(15);
person2.setName("飞飞"); List<Person> lp = new ArrayList<Person>();
lp.add(person1);
lp.add(person2);
System.out.println("{\"error\":"+"\"0\","+"\"parson\":"+serialize(lp)+"}");
} }