我想使用 volley JsonArrayRequest 进行带有参数的 GET 请求。我用参数调用 getParam() 方法,但它没有调用。
JsonArrayRequest jreq = new JsonArrayRequest(Request.Method.GET,"http://api.openchargemap.io/v2/poi/",null,
new Response.Listener<JSONArray>() {
@Override
public void onResponse(JSONArray response) {
Log.d("TAG", "" + response.toString());
if(response.toString().length() > 1) {
parseJson(response.toString());
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Log.d("TAG",""+error.toString());
}
})
{
@Override
protected Map<String, String> getParams() {
Map<String,String> map = new HashMap<String,String>();
map.put("output","json");
map.put("countrycode","US");
map.put("latitude","32.57933044");
map.put("longitude","-110.8514633");
map.put("maxresults","100");
map.put("distance","10");
map.put("distanceunit","KM");
map.put("compact","true");
map.put("verbose","false");
return map;
}
};
RequestQueue requestQueue = Volley.newRequestQueue(this);
requestQueue.add(jreq);
我没有得到适当的响应,因为凌空没有调用 getParam()。我在堆栈溢出方面进行了很多搜索,但没有得到正确的答案,而且凌空文档也不好。这就是为什么我在这里提出我的问题。谢谢。