0
我想檢索related_ids數組的數據,但未能這樣做。我的代碼不分別給我每個數組的值。通過json檢索數組數據
{
"title": "Prod"
"related_ids": [3]
0: 4323
1: 4321
2: 4317
"tags": [0]
}
這是我的代碼。
JSONArray jsonArray = response.getJSONArray("showProductListResponse");
for (int i = 0; i < jsonArray.length(); i++) {
try {
JSONObject obj = jsonArray.getJSONObject(i);
HomelList productListItems = new HomelList();
productListItems.setName(obj.getString("title"));
try {
JSONArray relatedimages = obj.getJSONArray("related_ids");
for (int j = 0; j < relatedimages.length(); j++) {
JSONObject relimagesObject = relatedimages.getJSONObject(j);
productListItems.setRelatedids(relimagesObject.getInt(relimagesObject.indexOf[j]);
}
} catch (JSONException e) {
e.printStackTrace();
}
gavkidata.add(productListItems);
adapter.notifyDataSetChanged();
} catch (JSONException e) {
e.printStackTrace();
}
}