![](/img/trans.png)
[英]How can I use these Node modules to accept HTML through a file or URL and then output JSON as validation of existing HTML elements?
[英]How can I use JSON file in html?
鏈接是這樣的: https://covid.ourworldindata.org/data/owid-covid-data.json我想用這個數據,比如說,計算總病例數的總和。 然后將案例的總和放入 html 文檔中。 但是在文件中它顯示了很多不同日期的案例。 我只想要最新的案例(最后一個案例)。 我怎樣才能做到這一點?
我想從每個區域中提取一個數據(例如感染病例總數),並對其進行求和
從你的評論。 無法幫助 HTML 部分,但我可以幫助邏輯部分。
let sum = 0;
Object.keys(data).forEach((key) => (sum += data[key].data[0].total_cases))
console.log(sum)
我不太明白你想要達到的目標。 我構建了一個小算法來簡化 JSON 大數據,這里是您收集數據的 output。 我希望它能幫助你操縱它。 當您澄清需要提取的數據時,我將編輯我的答案。
{
"AFG": {
"continent": "Asia",
"location": "Afghanistan",
"population": 38928341,
"population_density": 54.422,
"median_age": 18.6,
"aged_65_older": 2.581,
"aged_70_older": 1.337,
"gdp_per_capita": 1803.987,
"cardiovasc_death_rate": 597.029,
"diabetes_prevalence": 9.59,
"handwashing_facilities": 37.746,
"hospital_beds_per_thousand": 0.5,
"life_expectancy": 64.83,
"human_development_index": 0.498,
"data": [
{
"date": "2020-02-24",
"total_cases": 1,
"new_cases": 1,
"total_cases_per_million": 0.026,
"new_cases_per_million": 0.026,
"stringency_index": 8.33
}
]
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.