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) {
}
});
JsonObjectRequest
andJsonArrayRequest
is the right tool you need. However if it is a different format or you just wanted to use some other serialization/deserialization tool like GSON then theStringRequest
is the general tool for that. Well so far Volley is lacking ofByteRequest
. – Sovereign