Search code examples
phpjsonloaddecodefile-get-contents

Simple Json in PHP


I have a simple task that does not work I Have a json file..


Solution

  • When you decode with the 'true' bool as second param, you will get an associative array back. In your code snippet you then loop it out.
    What you should do, is skip the loop and just access the data from the assoc array right away:

    echo $array['navn'];
    
    
    // The JSON object:
    {"nr":"5250","navn":"Odense SV","adresser":"http://oiorest.dk/danmark/postdistrikter/5250/adresser"}
    // Is equivalent to this php assoc-array:
    array("nr" => "5250", "navn" => "Odense SV", "adresser" => "http://oiorest.dk/danmark/postdistrikter/5250/adresser");