Reputation: 13943
I am a little confused as to which I am supposed to use.
The API is an trying to hit accepts regular text post parameters although its response is a JSON String.
Which should I use ?
Upvotes: 2
Views: 2506
Reputation: 11
StringRequest - when you want to send api parameter (getParams()) and fetch json response, you can use StringRequest.
JsonObjectRequest - When you only want to fetch the json response and not pass an api parameter, you can use JsonObjectRequest. JsonObjectRequest can override the same set of methods (getHeaders(), getBodyContentType(), getBody(), getMethod()) like the StringRequest except getParams().
Upvotes: 0
Reputation: 108
JsonObjectRequest
and StringRequest
is different in their parent class and their response. You could find it out if you dig into volley's source code.
JsonObjectRequest extends JsonRequest<JSONObject>
StringRequest extends Request<String>
So, if the response is a JSON String, then you could just use JsonObjectRequest
for convenience, since Volley has wrapped the response to be a JSONObject
.
Upvotes: 2