Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/227.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Android类JsonRequest和子类JsonRequestArray和JsonRequestObject_Java_Android_Android Volley - Fatal编程技术网

Java Android类JsonRequest和子类JsonRequestArray和JsonRequestObject

Java Android类JsonRequest和子类JsonRequestArray和JsonRequestObject,java,android,android-volley,Java,Android,Android Volley,也许我的问题有点幼稚,因为我对安道尔很陌生。我试图使用类JsonRequestArray发送GET请求。我想随请求发送一些参数。我发现一些答案是“提出要求”。但是,我只想使用JsonRequestArray类。从它看来,我们需要在这里传递一些东西给构造函数来代替null: JsonObjectRequest jsObjRequest = new JsonObjectRequest(Request.Method.GET, url, null, new Response.Listener<JS

也许我的问题有点幼稚,因为我对安道尔很陌生。我试图使用类JsonRequestArray发送GET请求。我想随请求发送一些参数。我发现一些答案是“提出要求”。但是,我只想使用JsonRequestArray类。从它看来,我们需要在这里传递一些东西给构造函数来代替null:

JsonObjectRequest jsObjRequest = new JsonObjectRequest(Request.Method.GET, url, null, new Response.Listener<JSONObject>()
JsonObjectRequest jsObjRequest=newjsonobjectrequest(Request.Method.GET,url,null,new Response.Listener())

但是不清楚设置参数的参数应该是什么格式。我试图搜索类的JSONObjectArray的构造函数,但找不到。如果有任何帮助,我们将不胜感激。

不幸的是,android截击没有文档源,或者至少找不到文档源。因此我在是

以下是构造函数方法之一,您可以在jsonRequest中传递参数

JsonArrayRequest(int method, String url, JSONArray jsonRequest,
                        Listener<JSONArray> listener, ErrorListener errorListener)
JsonArrayRequest(int方法、字符串url、JSONArray-jsonRequest、,
监听器监听器,错误监听器(错误监听器)

如果您需要更多帮助,请告诉我。

IMO,您可以参考以下JavaDoc内容:

    /**
     * Creates a new request.
     * @param method the HTTP method to use
     * @param url URL to fetch the JSON from
     * @param jsonRequest A {@link JSONObject} to post with the request. Null is allowed and
     *   indicates no parameters will be posted along with request.
     * @param listener Listener to receive the JSON response
     * @param errorListener Error listener, or null to ignore errors.
     */
    public JsonObjectRequest(int method, String url, JSONObject jsonRequest,
            Listener<JSONObject> listener, ErrorListener errorListener) {
        super(method, url, (jsonRequest == null) ? null : jsonRequest.toString(), listener,
                errorListener);
    }
/**
*创建一个新请求。
*@param method要使用的HTTP方法
*@param url从中获取JSON
*@param jsonRequest A{@link JSONObject}与请求一起发布。允许Null,并且
*指示不会随请求一起发布任何参数。
*@param listener用于接收JSON响应
*@param errorListener Error listener,或null忽略错误。
*/
公共JSONObject请求(int方法、字符串url、JSONObject jsonRequest、,
监听器监听器,错误监听器(错误监听器){
super(方法,url,(jsonRequest==null)?null:jsonRequest.toString(),侦听器,
错误监听器);
}
如果您使用mcxiaoke的截击而不是Google的截击,那么您将拥有其他构造函数,例如:

    /**
     * Creates a new request.
     * @param method the HTTP method to use
     * @param url URL to fetch the JSON from
     * @param requestBody A {@link String} to post with the request. Null is allowed and
     *   indicates no parameters will be posted along with request.
     * @param listener Listener to receive the JSON response
     * @param errorListener Error listener, or null to ignore errors.
     */
    public JsonObjectRequest(int method, String url, String requestBody,
                             Listener<JSONObject> listener, ErrorListener errorListener) {
        super(method, url, requestBody, listener,
                errorListener);
    }
/**
*创建一个新请求。
*@param method要使用的HTTP方法
*@param url从中获取JSON
*@param requestBody A{@link String}与请求一起发布。允许Null,并且
*指示不会随请求一起发布任何参数。
*@param listener用于接收JSON响应
*@param errorListener Error listener,或null忽略错误。
*/
公共JsonObjectRequest(int方法、字符串url、字符串requestBody、,
监听器监听器,错误监听器(错误监听器){
超级(方法、url、请求体、侦听器、,
错误监听器);
}

谢谢您的回复。我想我们也可以在这里使用post方法。对吗?只是为了确认一下,如果我想将两个参数传递给p1和p1。那么我的调用应该是这样的:JSONArray postPara=new JSONArray({“p1”:“value1”,“p2”:“value2”});JsonArrayRequest(方法、url、postPara、侦听器、errorListener);最好在jsonObject中使用put()方法,然后调用toJSONArray()