首页 > Web开发 > 详细

简单易用的JSON与List相互转换

时间:2014-08-28 17:00:41      阅读:302      评论:0      收藏:0      [点我收藏+]

用系统自带包:org.json就可以

List集合封装了object,下面是list到json

/**
	 * 
	 * @param list
	 *            存放书签的集合
	 * @return json格式对象
	 */
	private static JSONObject listTojsoJsonObject(List<CalendarEvent> list) {
		JSONObject jsonObj = new JSONObject();
		try {
			jsonObj.put("calendarEvents", list);
		} catch (JSONException e) {
			// The JSONException is thrown by the JSON.org classes when things
			// are amiss.
			e.printStackTrace();
		}
		return jsonObj;
	}

下边是json到list

**
	 * 
	 * @param json
	 * @return list
	 * @throws JSONException
	 */
	public static List<CalendarEvent> jsonTolist(JSONObject json)
			throws JSONException {
		List<CalendarEvent> list = (List) json.get("calendarEvents");

		return list;
	}


简单易用的JSON与List相互转换

原文:http://blog.csdn.net/shaohx0518/article/details/38899651

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!