我的问题与JsonArrayRequest有关。我请求,但它给出了错误。怎么样?我创建了Toast,在那里我看到它给出了错误。我无法解决它。在我成功使用JsonObjectRequest之前。 所以,这是我的json:
[
{
"name" : "Chingiz Huseynzade",
"email" : "bla@bla.bla",
"phone" : {
"home" : "08947 000000",
"mobile" : "9999999999"
}
},
{
"name" : "Someone",
"email" : "tommy@gmail.com",
"phone" : {
"home" : "08946 000000",
"mobile" : "0000000000"
}
}]
这是我的代码:
RequestQueue rq = Volley.newRequestQueue(this);
JsonArrayRequest arrayreq = new JsonArrayRequest(url,
new Response.Listener<JSONArray>() {
@Override
public void onResponse(JSONArray response) {
for (int i = 0; i < 5; i++) {
try {
JSONObject jo = response.getJSONObject(i);
String name = jo.getString("name");
//PopularBooksImageAdapter.images.add(name);
System.out.println(name); //for test
} catch (JSONException e) {
e.printStackTrace();
}
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(getApplicationContext(), "Error!",
Toast.LENGTH_LONG).show();
}
});
rq.add(arrayreq);