具体JSON不会解析android工作室使用凌乱
问题描述:
最近我一直试图解析在android工作室使用凌空框架json。当我在阅读的教程中使用代码时,一切正常。但是,当我尝试解析我自己的json时,某些内容不起作用。具体JSON不会解析android工作室使用凌乱
这是我的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
的问题是,它根本不给输出。
在此先感谢
PS。这是我读的教程的网址https://www.thorntech.com/2016/03/parsing-json-android-using-volley-library/
答
您是否尝试记录响应并记录数据。
我认为Volley正在使用一个不是UI的线程,这就是为什么你不能从这里做一个setText。
答
对我来说,它正在努力设置文本从内凌空响应函数
我试图链接到您的JSON以下到TextView的,但是我最终下载,我是在我的电脑真的不舒服打开一个文件。所以,我无法检查JSON的有效性。尝试使用[json lint](https://jsonlint.com)等网站来检查JSON的有效性。同时查看您的日志数据或异常/错误(如果有的话)。如果它们存在,你应该发布这些。 –