发送JSONArray POST请求与Android凌空库JSONArray、POST、Android

2023-09-03 22:01:49 作者:等往事风中吹

我会发送和recive JSON数组与截击。 现在我可以recive阵列和它的确定。 但我不知道如何发送一个请求(例如:用post方法);

  JsonArrayRequest arrayReq =新JsonArrayRequest(URL,
            新的监听器和LT; JSONArray>(){

}
 

解决方案

Android的凌空队,之后可能会添加。但现在,你可以这样做:  创造你的类并扩展 JsonArrayRequest 那么你应该在此改变:

  @覆盖
保护地图<字符串,字符串> getParams()方法抛出AuthFailureError {
    HashMap的<字符串,字符串> PARAMS =新的HashMap<字符串,字符串>();
    params.put(名,价值);
    返回PARAMS;
}
 

然后作出新的构造:

 公共PostJsonArrayRequest(字符串URL,Response.Listener< JSONArray>听者,Response.ErrorListener errorListener){
    超(Method.POST,网址,空,监听器,errorListener);
}
 
JSONArray和JSONObject的区别

I would to send and recive json Array with volley. Now I can recive the array and it's ok. but I don't know how to send an request (For example : with post method ) ;

JsonArrayRequest arrayReq = new JsonArrayRequest(URL,
            new Listener<JSONArray>() {

}

解决方案

the android volley team maybe add it later . but for now you can do this : creat your class and extends JsonArrayRequest then you should overide :

    @Override
protected Map<String, String> getParams() throws AuthFailureError {
    HashMap<String, String> params = new HashMap<String, String>();
    params.put("name", "value");
    return params;
}

then make new constructor :

 public PostJsonArrayRequest(String url, Response.Listener<JSONArray> listener, Response.ErrorListener errorListener) {
    super(Method.POST, url, null, listener, errorListener);
}

 
精彩推荐
图片推荐