Skip to content Skip to sidebar Skip to footer

Volley Jsonarrayrequest Can Not Send Parameter To Server

I have a SearchActivity . i must send a parameter like search keyword to server and receive JsonArray . I used this code for JsonArrayRequest : JsonArrayRequest stringRequest = n

Solution 1:

Why you don't use StringRequest?

If your response is JsonArray or JsonObject you can get it from StringResponse as well.

String response;

JSONArray arrayResponse = newJSONArray(response);

Solution 2:

If your project uses mcxiaoke's library, you will find inside JsonArrayRequest.java file there's a constructor as below

publicJsonArrayRequest(int method, String url, JSONObject jsonRequest,
                        Listener<JSONArray> listener, ErrorListener errorListener) {
    super(method, url, (jsonRequest == null) ? null : jsonRequest.toString(), listener,
            errorListener);
}

Use this for your request.

If your app uses Google's volley library (not JAR file), you will need to add that constructor into JsonArrayRequest.java file, or you may try using getBody() instead of getParams().


UPDATE: use the following sample

...
JSONObject requestBody = newJSONObject();
try {
    requestBody.put("key1", "value1");
    requestBody.put("key2", "value2");  
    JsonArrayRequest request = newJsonArrayRequest(Request.Method.POST, url, requestBody, newResponse.Listener<JSONArray>() {
        @OverridepublicvoidonResponse(JSONArray response) {
            // do something
        }
    }, newResponse.ErrorListener() {
        @OverridepublicvoidonErrorResponse(VolleyError error) {
            // do something
        }
    };
    // Executes request
    requestQueue.add(request);
} catch (JSONException e) {
    // do something
}
...

Solution 3:

you can follow below link is much similar to you question.

Why is Volley's onResponse not called

Post a Comment for "Volley Jsonarrayrequest Can Not Send Parameter To Server"