嘿,每个人我想从JSON获取数据,但我无法得到..因为服务来到数组内部,所以任何人都有想法解决,请
"services":[{"main_category_id":"78","main_category_name":"Repairing",
"product": [{"product_id":"3","product_name":"Washing Machine",
我有代码,但只有产品数据,但服务数据异常
JSONArray contentServices = dataContent
.getJSONArray("services");
JSONObject Service_items = contentServices.getJSONObject(0);
List<CompanyServicesBean> jsonServicesList = new ArrayList<CompanyServicesBean>();
for (int j = 0; j < Service_items.length(); j++) {
JSONObject services = items.getJSONObject(j);
CompanyServicesBean serviceBean = new CompanyServicesBean();
serviceBean.setmain_category_id(services
.getString("main_category_id"));
ServiceBean.setmain_category_name(services
.getString("main_category_name"));
serviceBean.setproduct_id(services
.getString("product_id"));
serviceBean.setproduct_name(services
.getString("product_name"));
serviceBean.setduration_type(services .getString("duration_type"));
serviceBean.setduration_min(services
.getString("duration_min"));
}
答案 0 :(得分:2)
你有一个Json Object的服务数组 在每个Json对象中,theres是另一个数组产品
获得服务后
for (int j = 0; j < Service_items.length(); j++) {
JSONObject services = items.getJSONObject(j);
CompanyServicesBean serviceBean = new CompanyServicesBean();
}
您需要从serviceBean Object获取产品数组,如此
for (int j = 0; j < services.getJsonArray("product").length(); j++) {
JSONObject product = items.getJSONObject(j);
}