{
"status": "true",
"value": {
"products": [
{
"id": "1",
"store_categories_id": "10",
"description": "Chicken Briyani",
"unit_price": "120",
"pro_descripaation": "",
"pro_image": ""
},
{
"id": "2",
"store_categories_id": "10",
"description": "Vegetable Thali",
"unit_price": "100",
"pro_descripaation": "",
"pro_image": ""
}
]
}
}
錯誤:org.json.JSONException:指數2超出範圍[0..2)JSON指數2超出範圍的異常
try{
JSONArray product_array = value_array.getJSONArray("products");
for (int i = 0; i < response.length(); i++) {
if (status.equals("true")) {
// progressDialog.dismiss();
Toast.makeText(getApplicationContext(), value, Toast.LENGTH_SHORT).show();
} else if (status.equals("true")) {
// progressDialog.dismiss();
JSONObject jsonobject = product_array.getJSONObject(i);
ProductList productList = new ProductList();
productList.setDescription(jsonobject.getString(Constants.KEY_PRODUCT_DESCRIPTION));
productList.setId(jsonobject.getString(Constants.KEY_PRODUCT_ID));
Log.v("ganesh","keyboard");
productListArray.add(productList);
adapter.notifyDataSetChanged();
}
}
} catch (JSONException exception) {
// progressDialog.dismiss();
Log.e("--JSON EXCEPTION--", exception.toString());
}
任何一個可以幫助我理清這個問題?
我認爲你有上下文 – ganii
如何在上述上下文中使用product.length()? – ganii