您的位置:首页 > 其它

Volley使用笔记(二)

2016-06-14 03:11 260 查看
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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: