Android 结合嵌套json for循环
我有两个forloop,其中数据被添加到不同的ArrayList。现在我的问题是我们如何结合这两个arraylist? 下面是我尝试过的代码,但不起作用。请给我同样的解决方案。短暂性脑缺血发作Android 结合嵌套json for循环,android,json,arraylist,nested-for-loop,Android,Json,Arraylist,Nested For Loop,我有两个forloop,其中数据被添加到不同的ArrayList。现在我的问题是我们如何结合这两个arraylist? 下面是我尝试过的代码,但不起作用。请给我同样的解决方案。短暂性脑缺血发作 try { JSONObject object = new JSONObject(response); status = object.getString("status"); if (status.equals("200&qu
try {
JSONObject object = new JSONObject(response);
status = object.getString("status");
if (status.equals("200")) {
rest.dismissProgressdialog();
JSONArray jsonArray = object.getJSONArray("data");
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject jsonObject = jsonArray.getJSONObject(i);
New_Service_Model_1 new_service_model = new New_Service_Model_1();
new_service_model.setMain_name(jsonObject.getString("main_name"));
new_service_model.setSmid(jsonObject.optInt("smid"));
JSONArray jsonArray1 = jsonObject.getJSONArray("sub_service");
//sub_services_list.clear();
sub_services_list = new ArrayList<>();
for (int j = 0; j < jsonArray1.length(); j++) {
JSONObject jsonObject1 = jsonArray1.getJSONObject(j);
New_Sub_Service_Model_1 sub_service_model = new New_Sub_Service_Model_1();
sub_service_model.setSmid(jsonObject1.optString("smid"));
sub_service_model.setSbid(jsonObject1.optInt("sbid"));
sub_service_model.setSub_name(jsonObject1.optString("sub_name"));
sub_service_model.setDesc(jsonObject1.optInt("desc"));
sub_service_model.setSt_cust(jsonObject1.optInt("st_cust"));
sub_service_model.setSt_pro(jsonObject1.optInt("st_pro"));
sub_service_model.setExist_cust(jsonObject1.optInt("exist_cust"));
sub_service_model.setExist_prov(jsonObject1.optInt("exist_prov"));
sub_services_list.add(sub_service_model);
}
new_service_model.setSub_service_list(sub_services_list);
services_list.add(new_service_model);
service_list_adapter = new Service_List_Adapter_1(this, services_list, service_costMain_interface);
rclyrview_services.setAdapter(service_list_adapter);
service_list_adapter.notifyDataSetChanged();
}
} else {
rest.dismissProgressdialog();
Toast.makeText(Service_Manage.this, "No Data found", Toast.LENGTH_SHORT).show();
}
试试看{
JSONObject对象=新的JSONObject(响应);
status=object.getString(“status”);
如果(状态等于(“200”)){
rest.dismissProgressdialog();
JSONArray JSONArray=object.getJSONArray(“数据”);
for(int i=0;i
而不是手动解析json响应。
在这里粘贴json,并使用GSON或Jackson,以便于解析响应。
有很多教程可以让您快速了解如何完成工作。如果您的应用程序有很多地方需要进行Json解析,那么值得一试。将这两个arraylist结合起来到底是什么意思?正如我所看到的
子服务列表
在服务列表
中。我需要将所有数据收集在一起当我运行上面的代码时,服务列表总是空的。你能分享你的原始JSON响应吗?