解析json陣列
解析陣列有好幾種方法,,實際上都是一個道理;這裡給大家例兩個方法:
1.
try{ JSONArray jsonArray=new JSONArray(json); for (int i=0;i<jsonArray.length();i++){ JSONObject object = jsonArray.optJSONObject(i); Gson gson = new Gson(); DataDataBean bean = gson.fromJson(object + "", DataDataBean.class); List<DataDataBean.DataBean>2.data = bean.getData(); //清空集合,,實現下拉重新整理的效果 shulist.clear(); //新增到集合的頭部 shulist.addAll(0,data); } //設定介面卡 child_listview.setAdapter(new MyAdapter(shulist,getActivity())); //重新整理成功後停止重新整理 child_listview.onRefreshComplete(); } catch (Exception e) { e.printStackTrace(); }
Gson gson = new Gson(); Type type=new TypeToken<List<DataDataBean>>(){}.getType(); List<DataDataBean> beanList = gson.fromJson(json, type); List<DataDataBean.DataBean> dataList = beanList.get(0).getData(); child_listview.setAdapter(new MyAdapter(shulist,getActivity()));