Volley使用笔记(二)

来源:互联网 发布:联想笔记本网络开关 编辑:程序博客网 时间:2024/06/05 08:58

JsonRequest的用法与StringRequest相似。

JsonObjectRequest jsonObjectRequest = new JsonObjectRequest("http://m.weather.com.cn/data/101010100.html", null,          new Response.Listener<JSONObject>() {              @Override              public void onResponse(JSONObject response) {                  Log.d("TAG", response.toString());              }          }, new Response.ErrorListener() {              @Override              public void onErrorResponse(VolleyError error) {                  Log.e("TAG", error.getMessage(), error);              }          });            @Override              protected Map<String, String> getParams() throws AuthFailureError {          Map<String, String> map = new HashMap<String, String>();          map.put("params1", "value1");          map.put("params2", "value2");          return map;      }  

设置POST参数的方法除了getParams()还有一种

 HashMap<String, String> hashMap=new HashMap<String,String>();        hashMap.put("channelId",channelId);        hashMap.put("account", account);        JSONObject jsonParams =new JSONObject(hashMap);        JsonObjectRequest request=new JsonObjectRequest(Request.Method.POST, packUrl, jsonParams ,vif.loadingListener(),vif.errorListener());

其实可以直接写在构造函数中,添加参数Request.Method.POST,jsonParams

0 0
原创粉丝点击