Im using weather API.
I got JSON to an i coudlnt echo arrray one by one.
these the sample code to i used in my site
$json = file_get_contents(""); //$phparrya = json_decode($jsonstring); $array_json=json_decode($json, true); print_r($obj);

This problem is actually cause by the data is not in correct format. As the data provided is in {features: {forecast10day: 1 }} format while the json decode function accept {"features": {"forecast10day": 1}}

Member Avatar

What data did you want to extract? The textforecast/forecast data array would be:


For a 10 day forecast this contains 20 items - one daytime and one night for each day. It is number-indexed (0-19)

The simpleforecast/forecast data array would be:


For a 10 dat forecast, this contains 10 items - one whole day forecast for each day. It is number-indexed (0-9)

SO you could do...

$textfc = $array_json['forecast']['txt_forecast']['forecastday'];
$simplefc = $array_json['forecast']['txt_forecast']['simpleforecast'];

foreach($simplefc as $day)
    ...format items as you wish...
    $icon = "<img src='{$day['icon_url']}' />";

Try to workaround this code:


$json = file_get_contents("San_Francisco.json"); 
$array_json=json_decode($json, true); 


function display_jsonarray($array, $lvl_indent = 0)
    $indent = "";
    $istr = "    ";
    if($lvl_indent > 0)
        $indent = str_repeat($istr,$lvl_indent);
    foreach ($array as $key => $value)
            echo $indent.$key.": \n<br/>";
            $lvl_indent = $lvl_indent + 4;
            echo $indent.$key.": ".$value."\n";



With the display_jsonarray function i try to display recursiv the array but identation is'nt ok.
But maybe this code help you.