我无法弄清楚这个JSON
异常,通过排球从服务器检索到响应,我有一个类似的JSON
响应,它以这种方式解析,我似乎无法弄清楚为什么这会为product_id抛出无值异常。请帮助,提前谢谢
JSON响应:
{
status: "success",
data: [
{
product_id: "18",
cat_id: "3",
sub_id: "0",
username: "trial",
product_name: "Android Oreo",
description: "dummy text.",
amount: "2000.00",
btc_price: "0.000937",
image_url: "69273315-material-wallpapers16.png",
negotiable: "no"
},
{
product_id: "19",
cat_id: "3",
sub_id: "2",
username: "aa",
product_name: "Google Pixel XL",
description: "dummy text",
amount: "280000.00",
btc_price: "0.131220",
image_url: "img7.jpg",
negotiable: "no"
}
]
}
解析代码:
try {
JSONObject jsonObject = new JSONObject(response);
if (jsonObject.get("status").toString().equals("success")) {
JSONArray jsonarr = jsonObject.getJSONArray("data");
String columns[] = {"product_id", "cat_id", "sub_id", "username", "product_name",
"description", "amount", "btc_price", "image_url", "negotiable"};
for (int i = 0; i < jsonarr.length(); i++) {
ArrayList<String> temp = new ArrayList<>();
for (String column : columns) {
temp.add(jsonarr.getJSONObject(i).getString(column));
}
arr.add(temp);
shopAdapter.notifyDataSetChanged();
shopAdapter.setLoading();
}
} else if (jsonObject.get("status").toString().equals("end")) {
total = "end";
}
} catch (JSONException e) {
e.printStackTrace();
Toast.makeText(getActivity(), e.getMessage(), Toast.LENGTH_LONG).show();
}