我正在尝试在Android/Java应用程序中使用Volley(HTTP库)调用REST端点。这是我的代码:
RequestQueue queue = Volley.newRequestQueue(this);
String url ="https://covid19datasl.herokuapp.com/countries";
StringRequest stringRequest = new StringRequest(Request.Method.GET, url,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
System.out.println(response);
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
System.out.println("Error");
}
});
但是它给我返回了一个像这样的字符串响应:
[{"country":"USA","countryCode":"US"},{"country":"India","countryCode":"IN"},{"country":"Brazil","countryCode":"BR"}]
我怎样将这个 String
转换为可迭代对象?