如何在此JSON格式上使用Volley获取Http get请求

时间:2015-08-10 08:39:08

标签: android http get android-volley

重要提示:要忽略所有ID和键。它们是自动生成的。对于每一行,只有value属性相关 你。

{"total_rows":3,"offset":0,"rows":[
{"id":"0342fde43316bffdea32d0ec990dba4e","key":"0342fde43316bffdea32d0ec990dba4e","value":{"title":"My Idea","content":"I have to discuss my idea with the team"}},
{"id":"0342fde43316bffdea32d0ec990ee122","key":"0342fde43316bffdea32d0ec990ee122","value":{"title":"New project","content":"I need to call the customer"}},
{"id":"0342fde43316bffdea32d0ec990f168c","key":"0342fde43316bffdea32d0ec990f168c","value":{"title":"Birth day","content":"Buy a gift for my mom!"}}

]}

1 个答案:

答案 0 :(得分:0)

您可以使用此link

final String URL = "/volley/resource/12";
// Post params to be sent to the server
HashMap<String, String> params = new HashMap<String, String>();
params.put("token", "AbCdEfGh123456");

JsonObjectRequest req = new JsonObjectRequest(URL, new JSONObject(params),
       new Response.Listener<JSONObject>() {
           @Override
           public void onResponse(JSONObject response) {
               try {
                   VolleyLog.v("Response:%n %s", response.toString(4));
               } catch (JSONException e) {
                   e.printStackTrace();
               }
           }
       }, new Response.ErrorListener() {
           @Override
           public void onErrorResponse(VolleyError error) {
               VolleyLog.e("Error: ", error.getMessage());
           }
       });

// add the request object to the queue to be executed
ApplicationController.getInstance().addToRequestQueue(req);