Android排球|从多个网址中提取json

时间:2016-05-20 01:25:27

标签: android json parsing android-volley

我目前正在使用Volley使用以下代码提取json内容。

JsonArrayRequest servicesStatus = new JsonArrayRequest(url1,
            new Response.Listener<JSONArray>() {
                @Override
                public void onResponse(JSONArray response) {
                    Log.d(TAG, response.toString());
                    hidePDialog();

                    // Parsing json
                    for (int i = 0; i < response.length(); i++) {
                        try {

                            JSONObject obj = response.getJSONObject(i);
                            // Having obj to process further
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                    }
                    // notifying list adapter about data changes
                    // so that it renders the list view with updated data
                    adapter.notifyDataSetChanged();
                }
            }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            VolleyLog.d(TAG, "Error: " + error.getMessage());
            hidePDialog();

        }
    });

现在,我想为新网址添加一个json处理程序,并在从两个网址成功下载后关闭对话框。

我尝试复制粘贴上面的东西,url1替换为url2和不同的jsonarrayrequest名称。并在第二个中添加了hideDialog()。但第二个根本没有被召唤。

任何人都可以指导如何实现这一目标。

1 个答案:

答案 0 :(得分:2)

如果您想要多个请求,则必须添加请求到队列。你可以这样做:

   RequestQueue request =  Volley.newRequestQueue(Context);
   request.add(FirstRequest);
   request.add(SecondRequest);

这可以帮助您在Volley中添加多个请求。我希望这可以帮到你。谢谢你

相关问题