Javascript 如何选择要在html中显示的json数据
我有这个json数据URL,我只想选择要在html中显示的数据,但我不知道怎么做。请帮我做那件事 这是我的JAVASCRIPTJavascript 如何选择要在html中显示的json数据,javascript,html,json,api,Javascript,Html,Json,Api,我有这个json数据URL,我只想选择要在html中显示的数据,但我不知道怎么做。请帮我做那件事 这是我的JAVASCRIPT // API Fetch Call const api_url = './src/india.json'; async function getCcount() { const response = await fetch(api_url); const data = await response.json(); const {
// API Fetch Call
const api_url = './src/india.json';
async function getCcount() {
const response = await fetch(api_url);
const data = await response.json();
const {
cases,
active,
deaths,
recovered
} = data;
document.getElementById('t-count').textContent = cases;
document.getElementById('a-count').textContent = active;
document.getElementById('d-count').textContent = deaths;
document.getElementById('r-count').textContent = recovered;
}
getCcount();
如何仅选择要在HTML中显示的法国数据。使用fetch函数。您必须在数据
数组中找到具有国家
属性且值为法国
的对象,如下所示:
(异步()=>{
试一试{
const api_url='1〕https://coronavirus-19-api.herokuapp.com/countries';
const response=wait fetch(api_url);
如果(response.status!==200){
log(`Status Code:${response.Status}`);
返回;
}
const data=wait response.json();
常数{
案例,
活跃的,
死亡,
恢复
}=data.find(covid=>covid.country==='France');
document.getElementById('t-count')。textContent=cases;
document.getElementById('a-count')。textContent=active;
document.getElementById('d-count')。textContent=死亡;
document.getElementById('r-count')。textContent=已恢复;
}捕捉(错误){
log(`fetcherror:${err}`);
}
})();代码>
病例:
活跃:
死亡:
恢复: