I´m having problems with json, I don´t get why my code doesn´t work. I want to put the [secondary_text] => United Kingdom
into a php variable, but I´m getting this Notice all the time:
Notice: Trying to get property 'predictions' of non-object in C:.........\CCPSeven.php on line 153
My Code:
header('Content-Type: application/json');
$htmlj = file_get_html('https://maps.googleapis.com/maps/api/place/queryautocomplete/json?key=*****&input=London&language=en',false);
$jsondecode2 = json_decode($htmlj);
foreach ($jsondecode2 as $jsonforeach2) {
$Country = ($jsonforeach2->description->structured_formatting->secondary_text);
}
print_r($Country);
The Json:
stdClass Object
(
[predictions] => Array
(
[0] => stdClass Object
(
[description] => London, United Kingdom
[id] => *****+
[matched_substrings] => Array
(
[0] => stdClass Object
(
[length] => 6
[offset] => 0
)
)
[place_id] => ChIJdd4hrwug2EcRmSrV3Vo6llI
[reference] => *****
[structured_formatting] => stdClass Object
(
[main_text] => London
[main_text_matched_substrings] => Array
(
[0] => stdClass Object
(
[length] => 6
[offset] => 0
)
)
[secondary_text] => United Kingdom
)