php - Openweathermap: json (min and max temp) -
i want implement weather module website. chose "openweathermap".
i want min , max temperature today , tomorrow.
php
$json_string = file_get_contents("http://api.openweathermap.org/data/2.5/forecast/daily?q=london&mode=json"); $jsondata = json_decode($json_string, true); $min_1 = $jsondata['list'][0]['temp'][0]['min']; $max_1 = $jsondata['list'][0]['temp'][0]['max']; $min_2 = $jsondata['list'][1]['temp'][0]['min']; $max_2 = $jsondata['list'][1]['temp'][0]['max']; echo $min_1.' - '.$max_1.'<br><br>'; echo $min_2.' - '.$max_2.'<br><br>';
but code no output (except 2 "-").
json file
you're placing [0]
:
// v removed [0], temp doesn't have array in array $min_1 = $jsondata['list'][0]['temp']['min']; $max_1 = $jsondata['list'][0]['temp']['max']; $min_2 = $jsondata['list'][1]['temp']['min']; $max_2 = $jsondata['list'][1]['temp']['max']; echo $min_1.' - '.$max_1.'<br><br>'; echo $min_2.' - '.$max_2.'<br><br>';
to celsius, attach &units=metric
:
http://api.openweathermap.org/data/2.5/forecast/daily?q=london&mode=json&units=metric
Comments
Post a Comment