Created
March 8, 2020 17:47
-
-
Save IT-Berater/baf4216bda8876d50f3d5e483ebe750c to your computer and use it in GitHub Desktop.
Corona - Covid-19 JSON Java Sample
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package corona; | |
import java.io.IOException; | |
import java.net.MalformedURLException; | |
import java.net.URL; | |
import java.nio.charset.Charset; | |
import org.apache.commons.io.IOUtils; | |
import org.json.JSONException; | |
import org.json.JSONObject; | |
/** | |
* COVID-19 global data as-a-service https://covid19.mathdro.id | |
* | |
* Daten von: tinyurl.com/virus-corona | |
* | |
* This website and its contents herein, including all data, mapping, and | |
* analysis (“Website”), copyright 2020 Johns Hopkins University, all rights | |
* reserved, is provided to the public strictly for educational and academic | |
* research purposes. | |
* | |
* Api: https://covid19.mathdro.id/api | |
* | |
* https://github.com/mathdroid/covid19 | |
* | |
* License | |
* | |
* MIT License 2020, mathdroid. | |
* | |
* Transitively from the John Hopkins Site, the data may not be used for | |
* commercial purposes. | |
* | |
* @author Thomas Wenzlaff | |
*/ | |
public class Corona { | |
private static final String URL = "https://covid19.mathdro.id/api"; | |
public static void main(String[] args) throws JSONException, MalformedURLException, IOException { | |
JSONObject json = new JSONObject(IOUtils.toString(new URL(URL), Charset.forName("UTF-8"))); | |
// System.out.println(json.toString()); | |
int bestaetigt = getWert(json, "confirmed"); | |
int erholt = getWert(json, "recovered"); | |
int gestorben = getWert(json, "deaths"); | |
String zuletztAktuallisiert = json.getString("lastUpdate"); | |
System.out.println("Anzahl bestätigte Personen: " + bestaetigt + ", genesen: " + erholt + ", gestorben: " + gestorben + ", zuletzt aktuallisiert: " | |
+ zuletztAktuallisiert); | |
} | |
private static int getWert(JSONObject json, String key) { | |
JSONObject bestaetigt = (JSONObject) json.get(key); | |
int anzahl = bestaetigt.getInt("value"); | |
return anzahl; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment