在设置JSON文件时,我的代码中有错误
到目前为止,我对这一切都还是个新手。然而,我已经尝试使用我在网上找到的教程创建了一个新闻阅读器应用程序。它涉及在线托管和应用程序访问的JSON文件。
我在JsonObjectRequest
上有错误-无法解决请求-无法解决。然而,它说我可以添加一个导入。下载管理器-这是我想要实现的正确导入吗?看起来是这样,但我不能百分之百肯定,有人能澄清这一点吗?
Cannot resolve symbol Response.
response.getJSONArray("newsItems");
The error is Unhandled exception: org.json.JSONException
请求:
JsonObjectRequest myReq = new JsonObjectRequest(Request.Method.GET, "https://api.myjson.com/bins/z0lwn", (String)null,
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
JSONArray newsItems = response.getJSONArray("newsItems");
try {
for (int i = 0; i < newsItems.length(); i++) {
JSONObject temp = newsItems.getJSONObject(i);
}
}
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
}
});
转载请注明出处:http://www.intsu.net/article/20230429/2315690.html