如何通过按类别进行翻新,将json中的数据填充到嵌套的RecyclerView中?
我确实尝试使用两个函数通过嵌套的for循环来检索和填充。请给我一些有关如何填充json数据的示例。谢谢
@SuppressLint("WrongConstant")
private void writeRecycler(String jsonresponse) {
try{
// Getting the whole Json object from response
JSONObject obj = new JSONObject(jsonresponse);
ArrayList<SectionDataModel> sectionDataModelArrayList = new ArrayList<>();
JSONArray dataArray = obj.getJSONArray("data");
for (int i = 0; i < dataArray.length(); i ++){
SectionDataModel sectionDataModel = new SectionDataModel();
JSONObject dataobj = dataArray.getJSONObject(i);
sectionDataModel.setEqpName(dataobj.getString("equipment"));
ArrayList<SingleItemDataModel> singleItem = new ArrayList<SingleItemDataModel>();
for(int j = 0; j<singleItem.size(); j++){
SingleItemDataModel singleItemDataModel = new SingleItemDataModel();
JSONObject jobj = dataArray.getJSONObject(j);
singleItemDataModel.setChecklist(jobj.getString("Checklists"));
singleItemDataModel.setActivity(jobj.getString("Activity"));
singleItemDataModel.setStatus(jobj.getString("Status"));
}
sectionDataModel.setDescription(singleItem);
sectionDataModelArrayList.add(sectionDataModel);
}