【问题标题】:specific json wont parse android studio using volley特定的 json 不会使用 volley 解析 android studio
【发布时间】:2018-03-31 14:10:51
【问题描述】:

最近我一直在尝试使用 volley 框架在 android studio 中解析 json。当我使用我阅读的教程中的代码时,一切正常。但是,当我尝试解析自己的 json 时,有些东西不起作用。

这是我的 json 代码

JsonObjectRequest objectrequest = new JsonObjectRequest(hondenpoepURL, new Response.Listener<JSONObject>() {
        @Override
        public void onResponse(JSONObject response) {
            try {
                JSONObject type = response.getJSONObject("type");

                JSONArray features = response.getJSONArray("features");




                for (int i = 0; i < features.length(); i++) {

                    JSONObject bak = features.getJSONObject(i);

                    JSONObject geometry = bak.getJSONObject("geometry");
                    JSONArray coordinates = geometry.getJSONArray("coordinates");

                    double latitude = coordinates.getDouble(1);
                    double longitude = coordinates.getDouble(0);


                    data +=  "latitude: " + latitude + "\nlongitude: " + longitude +
                            "\n\n";

                }


                results.setText(data);

            } catch (JSONException e) {
                e.printStackTrace();
            }

        }
    },
            new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {
                    Log.e("Volley", "Error");
                }
            }


    );

    requestQueue.add(objectrequest);

这是我的 json 网址: http://portaal-gem-lwd.opendata.arcgis.com/datasets/1f505f23ef0a4f92aa32b0c8b98e8cbf_0.geojson

问题是它根本没有输出。

提前致谢

附言。这是我阅读的教程的网址https://www.thorntech.com/2016/03/parsing-json-android-using-volley-library/

【问题讨论】:

  • 我尝试点击指向您的 JSON 的链接,但最终下载了一个文件,我真的不习惯在我的计算机上打开该文件。所以,我无法检查 JSON 的有效性。尝试使用json lint 之类的网站来检查 JSON 的有效性。还要查看您的日志数据或异常/错误(如果有)。如果它们存在,您也应该发布它们。

标签: android json android-volley android-studio-2.3


【解决方案1】:

您是否尝试记录响应并记录数据。

我认为 Volley 使用的是不是 UI 的线程,这就是为什么你不能只从这里做一个 setText。

【讨论】:

    【解决方案2】:

    在我看来,它正在从凌空响应函数内部将文本设置为 textview

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-08-04
      • 1970-01-01
      • 2019-04-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-08-25
      相关资源
      最近更新 更多