【发布时间】:2014-11-24 11:02:44
【问题描述】:
我正在使用 json 根据邮政编码结果处理第 3 方 api。到目前为止,我已经得到了
$json = json_decode(file_get_contents($remote_url, false, $context))
从 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 )
上面的代码是json的结果。
如何将 postcode 的值设置为 $postcode...
我试过了:
$postcode = $json['result']['postcode'] or [0]['postcode']
并得到致命错误:
不能使用 stdClass 类型的对象作为数组。
请有人让我走上正确的道路。
【问题讨论】: