【问题标题】:Json Array in Volley AndroidVolley Android中的Json数组
【发布时间】:2018-05-05 06:54:35
【问题描述】:

我有一个统一资源定位器 (URL),其中包含 JSON 数组 [1579.39734, 2523,679.59824966966,4327116] 和键名。如何使用 volley 获取 JSON 数组的数据元素?有人可以帮忙吗?

以下是我的编码,但不起作用。

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


    }

【问题讨论】:

标签: android android-volley


【解决方案1】:

试试看

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

【讨论】:

    猜你喜欢
    • 2020-06-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-05-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-21
    相关资源
    最近更新 更多