如何使用json获取此数据 . 它是一个对象还是一个数组?我很迷惑 . 以下是我的数据以及我实施的内容 . 我无法得到任何 Value . 请帮我拿取值 .
JSONObject jobject = new JSONObject(response);
JSONArray jsonArray = jobject.getJSONArray("variety");
for (int i =0; i<=jsonArray.length();i++){
jobject= jsonArray.getJSONObject(i);
txt_today_671.setText(jobject.getString("variety.coc671"));
}
{
"status": 200,
"variety": {
"coc671": {
"today": 0,
"todate": 0
},
"co92005": {
"today": 0,
"todate": 0
},
},
"others": {
"today": 0,
"todate": 0
}
},
"distance": {
"0to20": {
"today": 0,
"todate": 0
},
"20to40": {
"today": 0,
"todate": 0
},
"above100": {
"today": 0,
"todate": 0
}
}
}
2 回答
这里,
variety
和distance
不是jsonArray,它是一个jsonObject .要遍历jsonObject,请遵循以下机制 -
对距离物体做同样的事情 -
Always remember JSONArray starts with [ and JSONObject start with {
只是向您说明一点,在演示中可能会出现拼写错误,