Android Class JsonRequest 和子类 JsonRequestArray 和 JsonRequestObject

Android Class JsonRequest and Subclasses JsonRequestArray and JsonRequestObject

可能是我的问题有点幼稚,因为我对 Andorid 还很陌生。我正在尝试使用 class JsonRequestArray 发送 GET 请求。我想随请求发送一些参数。我发现一些答案说要制作 customRequest。但是我只想使用 JsonRequestArray class 。从 Androids tutorial 看来我们需要传递一些东西给构造函数来代替这里的 null:

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

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

不幸的是,android-volley 没有文档来源,或者至少我找不到。所以我在这个 link.

找到了源代码

下面是构造方法之一,可以在jsonRequest中传入参数

JsonArrayRequest(int method, String url, JSONArray jsonRequest,
                        Listener<JSONArray> listener, ErrorListener errorListener)

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

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);
    }

如果你使用mcxiaoke的Volley而不是Google的Volley,那么你将有其他构造函数,例如:

    /**
     * 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);
    }