The image contains the data which has no array name and I need to get the data which is in the image using volley.Help me with the code for it.
Asked
Active
Viewed 74 times
-1

PSKP
- 1,178
- 14
- 28

Sasidhar Reddy.D
- 11
- 3
2 Answers
0
You have to use a JSONArrayRequest . When you parse the response, it's a ready to use JSONArray object. You can loop the array to get your JSONObject items by position.
This has been covered in this thread -> Volley - Sending a POST request using JSONArrayRequest

Steve NDENDE
- 19
- 1
- 9
0
String url="https://earthquake.usgs.gov/archive/product/nearby-cities/ci39269503/ci/1593242325224/nearby-cities.json"; JsonArrayRequest jsonArrayRequest=new JsonArrayRequest(Request.Method.GET, url, new Response.Listener() { @Override public void onResponse(JSONArray response) { StringBuilder stringBuilder=new StringBuilder();
try {
for (int i=0;i<response.length();i++){
JSONObject citiesjsonObject=response.getJSONObject(i);
stringBuilder.append("Name : "+citiesjsonObject.getString("name")+
"\n"+"Distance : "+citiesjsonObject.getString("distance")+ "\n"
+"Population : "+citiesjsonObject.getString("population"));
stringBuilder.append("\n\n");
}
} catch (JSONException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
}
});
requestQueue.add(jsonArrayRequest);

Sasidhar Reddy.D
- 11
- 3