public static List getAllNewsFromNetwork(Context context) {
final List list = new ArrayList();
RequestQueue queue = Volley.newRequestQueue(context);
final JsonObjectRequest request = new JsonObjectRequest(URL, null, new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
Log.e(TAG, "response: " + response);
try {
JSONObject result = response.getJSONObject("result");
JSONArray array = result.getJSONArray("data");
Log.e(TAG, "array: " + array);
for (int i = 0, len = array.length(); i < len; i++) {
JSONObject object = (JSONObject) array.opt(i);
Log.e(TAG, "object: " + object);
NewsInfo info = new NewsInfo();
info.setTitle(object.getString("title"));
info.setThumbnail_pic_s(object.getString("thumbnail_pic_s"));
info.setThumbnail_pic_s02(object.getString("thumbnail_pic_s02"));
info.setThumbnail_pic_s03(object.getString("thumbnail_pic_s03"));
info.setDate(object.getString("date"));
info.setType(object.getString("realtype"));
info.setUrl(object.getString("url"));
Log.e(TAG, "onResponse: info.toString() ==" + info.toString());
list.add(info);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Log.e(TAG, "onErrorResponse: " + error);
}
});
queue.add(request);
queue.start();
Log.e(TAG, "getAllNewsFromNetwork: list.size() ==" + list.size());
return list;
}
这个函数返回的list为什么是空的?response输出的数据一直都有,解析也没出现问题,
求大神指教