I am using json to process a 3rd party api based on post code results. So far I have got
$json = json_decode(file_get_contents($remote_url, false, $context))
which provides the following results from a print_r:
stdClass Object ( [result] => stdClass Object ( [copyrightNotice] => © 2013-2014 StreetCheck. All Rights Reserved. Contains Ordnance Survey, Royal Mail, National Statistics and Land Registry data © Crown copyright and database right 2014. [postcode] => SN5 5RF [point] => stdClass Object ( [latitude] => 51.564896985 [longitude] => -1.837017086 ) [street] => Percheron Close [street2] => [locality] => Shaw [locality2] => [postTown] => Swindon [fullLocation] => Percheron Close, Shaw, Swindon, SN5 5RF [country] => England [outputArea] => E00078711 [largeUser] => [active] => 1 [ward] => stdClass Object ( [code] => E05002164 [name] => Shaw and Nine Elms ) [constituency] => stdClass Object ( [code] => E14000947 [name] => South Swindon ) [region] => stdClass Object ( [code] => E15000009 [name] => South West ) [commentary] => Percheron Close in Shaw is in the South West region of England. The postcode is within the Shaw and Nine Elms ward/electoral division, which is in the constituency of South Swindon. [urbanClassification] => Urban ) [message] => OK [success] => 1 )
Where the code above is the result from json.
How do I set the value of postcode to $postcode...
I have tried:
$postcode = $json['result']['postcode'] or [0]['postcode']
and got Fatal error:
Cannot use object of type stdClass as array in.
Could someone put me on right path please.