What is the difference between JSONRequest and StringRequest in volley
StringRequest class will be used to fetch any kind of string data. The response can be json, xml, html,text.
// Request a string response from the provided URL.
StringRequest stringRequest = new StringRequest(Request.Method.GET, URL,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
// Display the first 500 characters of the response string.
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
}
});
If you are expecting json object in the response, you should use JsonObjectRequest .
JsonObjectRequest jsonObjReq = new JsonObjectRequest(Method.GET,
URL, null,
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
Log.d(TAG, response.toString());
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
}
});