POST JSONObject to server and get String volley

51 views
Skip to first unread message

Jakub Kubkowski

unread,
Apr 15, 2021, 2:52:19 PM4/15/21
to Volley Users
Hello !
I try to post JSONObject ot my server, but  I have a problem, because my server response with String(can not change that ), not JSONObject.

val jsonObjectRequest = JsonObjectRequest(Request.Method.POST, url, jsonObj, object : Response.Listener<JSONObject?> { override fun onResponse(response: JSONObject?) { try { println(response.toString()) } catch (e: JSONException) { e.printStackTrace() } } }, object : Response.ErrorListener { override fun onErrorResponse(error: VolleyError) { error.printStackTrace() Log.d("JsonObjectErr", error.toString()); } } ) requestQueue.add(jsonObjectRequest)

}
I use standard request, but there is a way to quickly get what I want.
Please, I try almost everything from Stack.
I use Kkotlin and Java 

Jeff Davidson

unread,
Apr 15, 2021, 4:46:32 PM4/15/21
to Jakub Kubkowski, Volley Users
JsonObjectRequest is explicitly built around the assumption that the response will be JSON.

If you just want a regular string response, create a subclass of JsonRequest<String>, pass the JSON request body you want to the constructor, and implement parseNetworkResponse by parsing the response.data byte array as a String just like StringRequest does.

--
You received this message because you are subscribed to the Google Groups "Volley Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to volley-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/volley-users/1886f53f-64ac-422b-8a98-280a437110c6n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages