日期:2014-05-16 浏览次数:20371 次
public static void main(String[] args) { // TODO Auto-generated method stub MyObject obj = new MyObject(); obj.setProvinceID(1000); obj.setProvinceName("测试"); List tmplist = new ArrayList(); for(int a=0;a<2;a++){ MyObject tmp = new MyObject(); tmp.setProvinceID(a); tmp.setProvinceName("tmp"+a); tmplist.add(tmp); } obj.setObj(tmplist); String json = JSON.toJSONString(obj); System.out.println(json); MyObject tmpObj = JSON.parseObject(json,MyObject.class); System.out.println(tmpObj.getProvinceID()+"\t"+tmpObj.getProvinceName()+"\t"+tmpObj.getObj().size()); }
{"obj":[{"provinceID":0,"provinceName":"tmp0"},{"provinceID":1,"provinceName":"tmp1"}],"provinceID":1000,"provinceName":"测试"} 1000 测试 2