首页 > 解决方案 > Json Array in Volley Android

问题描述

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);


    }

标签: androidandroid-volley

解决方案


试试看

for(int i = 0; i< jsonArray.lenght(); i++){
    double value = jsonArray.getDouble(i);
}

推荐阅读