Reputation: 1
i had a Uniform Resource Locator (URL) that contain JSON
Array of [1579.39734, 2523,679.59824966966,4327116]
with key name. How can i get the data element of the JSON Array using volley? Can anyone help?
Below is my coding but is not working.
private void loadJsonArray() {
JsonArrayRequest jsArrayRequest = new JsonArrayRequest
(Request.Method.POST, new_url, null, new Response.Listener<JSONArray>() {
@Override
public void onResponse(JSONArray response) {
double[] value=new double[3];
pDialog.dismiss();
for (int count =0; count < response.length(); count++) {
try {
value[count]=response.getDouble(count);
}
catch (JSONException e) {
e.printStackTrace();
}
}
text1.setText(String.valueOf(value[0]));
text2.setText(String.valueOf(value[1]));
text3.setText(String.valueOf(value[2]));
text4.setText(String.valueOf(value[3]));
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(getApplicationContext(), "Error....", Toast.LENGTH_SHORT).show();
error.printStackTrace();
}
});
Singleton.getistance(this).addToRequestque(jsArrayRequest);
}
Upvotes: 0
Views: 80
Reputation: 91
try it
for(int i = 0; i< jsonArray.lenght(); i++){
double value = jsonArray.getDouble(i);
}
Upvotes: 1