Tôi không thể tìm thấy câu trả lời chi tiết cho câu hỏi này, hoặc ít nhất không phải là câu trả lời tôi có thể hiểu được.Cách lấy và phân tích cú pháp đối tượng JSON bằng Volley
Tôi đang cố gắng thiết lập Volley để kéo xuống các đối tượng JSON từ iTunes. Sau đó tôi muốn phân tích cú pháp các đối tượng, để lấy URL hình ảnh của họ.
Vì vậy, ví dụ, đây là sáng iTunes JSON đối tượng URL
String url = "https://itunes.apple.com/search?term=michael+jackson";
Vì vậy, ở đây tôi đã thiết lập mã của tôi để có được đối tượng này (sử dụng một hướng dẫn tất nhiên)
String url = "https://itunes.apple.com/search?term=michael+jackson";
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);
Các tuyên bố cuối cùng là
Volley.newRequestQueue(this).add(jsonRequest);
Có lẽ, bây giờ tôi có đối tượng JSON? Nhưng làm thế nào tôi có thể truy cập và phân tích nó?
Nó đã giúp bạn! Cảm ơn nhiều. –