码迷,mamicode.com
首页 > Web开发 > 详细

JSON JSONObject.fromObject JSONArray.fromObject

时间:2015-09-19 13:38:00      阅读:152      评论:0      收藏:0      [点我收藏+]

标签:

	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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!