【发布时间】: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