问题描述
我采用了文档中的示例代码,即来自 youtube 视频的代码。在新的响应中什么也没有发生。侦听器和 onResponse 函数甚至没有被调用。即使我在里面放了一个断点也无法调试它,不明白什么不起作用,onErrorResponse函数或try-catch块中没有捕获错误。
代码:
ListView statlist;
RecyclerView recyclerView;
String dcritical,dpositive,dtoday_cases,dtotal_deaths,dtotalcases,dtotal_countries,test;
public void FetchAPI_Data()
{
// String url = "https://corona.lmao.ninja/v2/all";
String url = "https://corona.lmao.ninja/v2/all/";
JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.GET,url,null,new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
try {
test = response.toString();
JSONObject jsonObject = new JSONObject(response.toString());
Log.d("JSON",jsonObject.getString("recovered"));
String recovered = jsonObject.getString("recovered");
Log.d("RECOVERED",recovered.toString());
String critical = jsonObject.getString("critical");
String positive = jsonObject.getString("active");
String today_cases = jsonObject.getString("todayCases");
String total_deaths = jsonObject.getString("deaths");
String total_countries = jsonObject.getString("affectedCountries");
String totalcases = jsonObject.getString("cases");
dcritical = critical;
dpositive = positive;
dtoday_cases = today_cases;
dtotal_deaths = total_deaths;
dtotal_countries = total_countries;
dtotalcases = totalcases;
} catch (JSONException e) {
e.printstacktrace();
}
}
},new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
}
});
RequestQueue requestQueue = Volley.newRequestQueue(this);
requestQueue.add(jsonObjectRequest);
//GlobalStatsData data= new GlobalStatsData(dcritica);
//return data;
}
JSON 响应格式
{
"updated": 1621228955561,"cases": 163724238,"todayCases": 12591,"deaths": 3393440,"todayDeaths": 222,"recovered": 143348966,"todayRecovered": 31533,"active": 16981832,"critical": 102549,"casesPerOneMillion": 21004,"deathsPerOneMillion": 435.3,"tests": 2324559552,"testsPerOneMillion": 297062.96,"population": 7825140972,"oneCasePerPeople": 0,"oneDeathPerPeople": 0,"oneTestPerPeople": 0,"undefined": 0,"activePerOneMillion": 2170.16,"recoveredPerOneMillion": 18319.03,"criticalPerOneMillion": 13.11,"affectedCountries": 222
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)