Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何选择要在html中显示的json数据_Javascript_Html_Json_Api - Fatal编程技术网

Javascript 如何选择要在html中显示的json数据

Javascript 如何选择要在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 {

我有这个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 {
         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}`);
}
})();
病例:
活跃:
死亡:
恢复: