質問

Can we post JsonObject or JsonArray using Android volley to the server?If yes can anyone please send the working sample. If i post string then it works fine but i have some problem while posting jsonObject or jsonArray.

役に立ちましたか?

解決

Yes you can. The JSON is added to the body of a POST request, like this:

JSONObject jsonObject; // your JSON here
requestQueue.add(new JsonObjectRequest(Method.POST, url, jsonObject, listener, errorListener);

他のヒント

Yes, just add data to JSONObject and pass that object in the request.

JSONObject jsonObject = new JSONObject();

        jsonObject.put("name", name);
        jsonObject.put("password", password);

        RequestQueue queue = Volley.newRequestQueue(context);
        JsonObjectRequest jsObjRequest = new JsonObjectRequest(Request.Method.POST, URL, jsonObject, new Response.Listener<JSONObject>() {
            @Override
            public void onResponse(JSONObject response) {
 Log.i("volley", "response: " + response);
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                 Log.i("volley", "error: " + error);
            }
        });
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top