我试图设置凌空从iTunes中下拉这个JSONObject
String url = "https://itunes.apple.com/search?term=michael+jackson";
重点是解析对象以获取特定歌曲的专辑艺术网址
所以我设置这个代码来获取JsonObject,并且我得到了一些错误
Cannot resolve symbol ErrorListener
Cannot resolve symbol Listener
以下是带注释错误的代码
JsonObjectRequest jsonRequest = new JsonObjectRequest
(Request.Method.GET, url, null, new Downloader.Response.Listener // Cannot resolve symbol Listener
<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
// the response is already constructed as a JSONObject!
try {
response = response.getJSONObject("args");
String site = response.getString("site"),
network = response.getString("network");
System.out.println("Site: "+site+"\nNetwork: "+network);
} catch (JSONException e) {
e.printStackTrace();
}
}
}, new Downloader.Response.ErrorListener // Cannot resolve symbol ErrorListener
() {
@Override
public void onErrorResponse(VolleyError error) {
error.printStackTrace();
}
});
Volley.newRequestQueue(this).add(jsonRequest);
答案 0 :(得分:1)
尝试Response.ErrorListener
http://afzaln.com/volley/com/android/volley/Response.ErrorListener.html
没有Downloader.ResposneListener
答案 1 :(得分:0)
更改为
StringRequest stringRequest =新的StringRequest(DownloadManager.Request.Method.GET,URL,
到
StringRequest stringRequest =新的StringRequest(com.android.volley.Request.Method.GET,URL,
您的代码将是
JsonObjectRequest jsonRequest = new JsonObjectRequest
(Request.Method.GET, url, null, new com.android.volley.Response.Listener // CHANGES HERE
<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
// the response is already constructed as a JSONObject!
try {
response = response.getJSONObject("args");
String site = response.getString("site"),
network = response.getString("network");
System.out.println("Site: "+site+"\nNetwork: "+network);
} catch (JSONException e) {
e.printStackTrace();
}
}
}, new com.android.volley.Response.ErrorListener // CHANGES HERE
() {
@Override
public void onErrorResponse(VolleyError error) {
error.printStackTrace();
}
});
Volley.newRequestQueue(this).add(jsonRequest);