Skip to content

Instantly share code, notes, and snippets.

@IT-Berater
Created March 8, 2020 17:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save IT-Berater/baf4216bda8876d50f3d5e483ebe750c to your computer and use it in GitHub Desktop.
Save IT-Berater/baf4216bda8876d50f3d5e483ebe750c to your computer and use it in GitHub Desktop.
Corona - Covid-19 JSON Java Sample
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