JSONObject和JSONArray

1:JSON格式数据如下

{"ticketInfos":[{"name":"刚刚","menPiaoType":"免费门票","price":0},{"name":"刚刚","menPiaoType":"免费门票","price":0}]}

if (etc.getTicketDetailJson() != null && "".equals(etc.getTicketDetailJson())) {
	JSONObject myJsonObject = new JSONObject(etc.getTicketDetailJson());
	JSONArray jsonarry = (JSONArray) myJsonObject.get("ticketInfos");
	for (int i = 0; i < jsonarry.length(); i++) {
	TicketDetail ticketDetail = new TicketDetail();
	JSONObject jObject = (JSONObject) jsonarry.get(i);
	ticketDetail.setName(jObject.get("name").toString());
	ticketDetail.setMenPiaoType(jObject.getString("menPiaoType").toString());
						 
	price = Integer.parseInt(jObject.get("price").toString());
	break;
		}
}

  

posted @ 2016-09-21 15:12  阿若蜜意  阅读(220)  评论(0编辑  收藏  举报