In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article focuses on "how to use the .NET Core to obtain and display the latest epidemic data", interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to use .NET Core to obtain and display the latest epidemic data.
Preface
The appearance of novel coronavirus really makes people nervous. I check today's latest data early in the morning, but every time the data are very heart-wrenching. Today, I suddenly want to look at the historical data of the past, but as a result, a lot of information is not very complete. Anyway, the state asked us to stay at home and make contributions, so we could do more research. By chance, we found an API that could find historical data, so we realized it with .NET Core 3.1.
Coding and implementation
By looking at the returned data, you can see that the data is in the standard JSON format, which reduces more work. The returned data is shown in the following figure:
Through the analysis of its data structure, we can know that it mainly has the following properties:
LastUpdateTime: string, latest update time
ChinaTotal: object, data summary
ChinaAdd: object, add data summary
ChinaDayList: array, daily historical data
ChinaDayAddList: array, add new historical data every day
AreaTree: array, regional data (including data from domestic provinces and cities and foreign countries)
Details of the project are as follows:
Finally, there is the coding implementation, which is relatively simple if you get the data, which can be quickly implemented using HttpClient+Newtonsoft.Json. It is important to note that the data returned by this interface needs to be deserialized twice.
The running effect is as follows:
Output after formatting and displaying the data:
Finally, save the data we need, and this is even easier:
Private static void SaveToFile (nCoVData data) {if (! File.Exists ("data.json")) {using (FileStream fs = new FileStream ("data.json", FileMode.Create, FileAccess.Write)) {using (StreamWriter sw = new StreamWriter (fs)) {sw.Write (data.Data); sw.Flush (); sw.Close () } else {using (FileStream fs = new FileStream ("data.json", FileMode.Open, FileAccess.Write)) {using (StreamWriter sw = new StreamWriter (fs)) {sw.Write (data.Data); sw.Flush (); sw.Close () }
Full code address: https://github.com/edison0621/2019nCoVData
At this point, I believe you have a better understanding of "how to use .NET Core to obtain and display the latest epidemic data". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.