final ArrayList<String> pic = new ArrayList<String>();
final ArrayList<String> name = new ArrayList<String>();
RequestQueue mQueue = Volley.newRequestQueue(this);
JsonArrayRequest req = new JsonArrayRequest(url,
new Response.Listener<JSONArray>() {
@Override
public void onResponse(JSONArray response) {
try {
for (int i = 0; i < response.length(); i++)
{
JSONObject jobj = response.getJSONObject(i);
name.add(jobj.getString("name"));
pic.add(jobj.getString("pic"));
}
txt1.setText(name.toString());
}
catch (JSONException e) { }
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Log.d("TAG", "Error: " + error.getMessage());
}
});
txt.setText(pic.toString());
mQueue.add(req);
尝试中的 name.toString
不为空(例如:[a,b,c,d]),但如果我将其移出,请尝试pic.toString
数组为空(例如:[])