JsonArrayRequest没有在Android Volley中使用响应方法

时间:2016-07-23 21:57:25

标签: android json android-volley

朋友们,我有一个关注来自Web服务的JSON数组响应,我希望从数据库中逐行读取所有数据并显示在Android Activity上。

[{"id":"2","type":"0","title":"Recruitment at ADANI Port, Mundra","date":"2016-07-01"},{"id":"1","type":"1","title":"Training at DAICT, Gandhinager","date":"2016-07-04"}]

我在使用Volley Library的Activity的onCreate()中实现了以下代码,该代码不显示输出,据我所知它不会调用onResponse()方法。

    public void getNews(){
    String url = "http://www.ABCDXYZ.net/tponews.php?tponews=1";
    Log.e("URL",url);

    requestQueue = Volley.newRequestQueue(this);


    JsonArrayRequest jor = new JsonArrayRequest(Request.Method.GET, url, null,
            new Response.Listener<JSONArray>() {
                @Override
                public void onResponse(JSONArray response) {
                    try {
                        Log.e("Resposne", "We have got the response");
                        JSONObject val = response.getJSONObject(0);
                    }catch (JSONException e){e.printStackTrace();}
                }
            },
            new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {
                    Log.e("Volley",error.toString());
                }
            }
    );
    requestQueue.add(jor);
}

输出只是Log.e中的URL(“URL”,url); //网址:www.ABCXYZ.net/tponews.php?tponews=1

0 个答案:

没有答案