Hallo.
Ich möchte aus einer JSON URL einzelne Werte in eine PHP Variable speichern
Irgendwie komme ich nicht weiter, kann mir jemand einen Tipp geben.
Die JSON Datei lasse ich ausgeben.
Ich möchte aus einer JSON URL einzelne Werte in eine PHP Variable speichern
Irgendwie komme ich nicht weiter, kann mir jemand einen Tipp geben.
PHP-Code:
<?php
// JSON auslesen
$url = "https://api.corona-zahlen.org/districts/09362";
$json = file_get_contents($url);
$data = json_decode($json, true);
// Datei mal ausgeben
echo"<pre>";
var_dump($data);
echo"</pre>";
// Werte ausgeben
foreach ($data as $element) {
echo $element["name"] ;
echo "<br>";
echo $element["deaths"] ;
}
?>
HTML-Code:
array(2) { ["data"]=> array(1) { ["09362"]=> array(14) { ["ags"]=> string(5) "09362" ["name"]=> string(10) "Regensburg" ["county"]=> string(13) "SK Regensburg" ["state"]=> string(6) "Bayern" ["population"]=> int(153094) ["cases"]=> int(6935) ["deaths"]=> int(82) ["casesPerWeek"]=> int(40) ["deathsPerWeek"]=> int(0) ["stateAbbreviation"]=> string(2) "BY" ["recovered"]=> int(6733) ["weekIncidence"]=> float(26.127738513593) ["casesPer100k"]=> float(4529.8966647942) ["delta"]=> array(3) { ["cases"]=> int(5) ["deaths"]=> int(0) ["recovered"]=> int(3) } } } ["meta"]=> array(5) { ["source"]=> string(20) "Robert Koch-Institut" ["contact"]=> string(35) "Marlon Lueckert (m.lueckert@me.com)" ["info"]=> string(42) "https://github.com/marlon360/rki-covid-api" ["lastUpdate"]=> string(24) "2021-06-06T00:00:00.000Z" ["lastCheckedForUpdate"]=> string(24) "2021-06-06T10:21:54.526Z" } }
Kommentar