美文网首页
#JSONObject原生解析

#JSONObject原生解析

作者: 小慧sir | 来源:发表于2019-07-13 14:19 被阅读0次
//获得JSONObject对象
JSONObject object = new JSONObject(lent);
//解析的类型 为  集合
JSONArray array = object.getJSONArray("results");
//创建空集合
List<Mdemo.ResultsBean>  listarra=new ArrayList<>();
//遍历  array
for (int i = 0; i < array.length(); i++) {
//获得每个 JSON串
JSONObject arrayJSONObject = array.getJSONObject(i);
//获得对象
Mdemo.ResultsBean  duixiang=new Mdemo.ResultsBean();
//用对象获得要解析的字段
duixiang.setUrl(arrayJSONObject.optString("url"));
duixiang.setDesc(arrayJSONObject.optString("desc"));
//添加到空集合
listarra.add(duixiang);
//创建适配器
Mvpadapter mvpadapter = new Mvpadapter(listarra);
//绑定适配器
mViewpagerView.setAdapter(mvpadapter);
      }

相关文章

网友评论

      本文标题:#JSONObject原生解析

      本文链接:https://www.haomeiwen.com/subject/rlapkctx.html