【发布时间】:2020-01-21 19:31:44
【问题描述】:
我正在使用 Volley 库来了解如何使用 JSON 数据,我已成功检索到一些数据,并且想知道如何从我的 json 数组中获取单个数据?我已经尝试按照用户在之前的 stackover flow 帖子中的建议进行操作,但只显示了 json 数组数据
@Override
public void downloadJson() {
final String url = "https://dog.ceo/api/breeds/image/random/2";
JsonObjectRequest getRequest = new JsonObjectRequest(Request.Method.GET, url, null,
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
try {
JSONArray jsonArray = response.getJSONArray("message");
Log.i("jsonArray", jsonArray.toString());
for(int i=0; i>jsonArray.length(); i++){
JSONObject object = jsonArray.getJSONObject(i);
Log.i("obj", object.toString());
}
} catch (JSONException e) {
e.printStackTrace();
}
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
}
}
);
requestQueue.add(getRequest);
}
【问题讨论】:
标签: android json android-volley android-json