无法在Android中使用[Volley Library]获取JSON数据

问题描述 投票:1回答:1

jason数组请求代码如下:

     JsonArrayRequest arrayRequest = new JsonArrayRequest(Request.Method.GET,url, (JSONArray) null , new Response.Listener<JSONArray>() {
            @Override
            public void onResponse(JSONArray response) {
                try {
                    Log.d("Response:", String.valueOf(response.getJSONObject(0)));
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                Toast.makeText(context, "Response not recieved", Toast.LENGTH_SHORT).show();
            }
        });

而且我使用了请求队列的单例实例来获取数据,

AppController.getInstance(context.getApplicationContext()).addToRequestQueue(arrayRequest);

[我正在使用提供大量问题的api服务(api会生成一个url,该url返回JSON对象,一个数组的集合(只需尝试打开url链接,就会看到json数组)]

但是当我运行该应用程序时,请求甚至没有得到响应,程序流进入了错误列表框。

有人可以解释这种行为吗?是因为url提供的JSON数组具有嵌套数组吗?为什么?

我尝试在这里阅读和分析其他问题,可能有同样的问题,但我什么也没发现。

android arrays json android-volley
1个回答
2
投票
您只想将

JsonArrayRequest更改为JsonObjectRequest

© www.soinside.com 2019 - 2024. All rights reserved.