第一次处理Json数组,包含了多个Json对象,以下是实例:
要处理的Json数组:
[{“goodsId”:34,“name”:“课程1111”,“price”:0,“property”:"",“quantity”:12,“types”:1},{“goodsId”:344,“name”:“课程1111”,“price”:0,“property”:"",“quantity”:12,“types”:1},{“goodsId”:344,“name”:“课程1111”,“price”:0,“property”:"",“quantity”:12,“types”:1}]
JSONArray ja = JSONArray.parseArray(goodsDetail);
for(int i = 0; i < ja.size(); i++){
JSONObject jo = ja.getJSONObject(i);
orderInfoList.add(new OnlineCourseOrderInfo(jo.getInteger("goodsId")
,jo.getInteger("quantity")
,jo.getString("name")
,jo.getInteger("price")
,jo.getInteger("types")));
}
另外也可以用另一种方式处理:
传参为要处理的Json数组和JSONObject.class,第二个传参规定了List<>数组中泛型的类型
List<JSONObject> jsonObjects = JSONArray.parseArray(fullScreenGoods, JSONObject.class);
记录一下处理方式