douzhao7014 2014-11-24 11:02
浏览 28

使用json数组中的api结果

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.

  • 写回答

3条回答 默认 最新

  • douzhi2012 2014-11-24 11:05
    关注

    These are standard objects not arrays.

               $json->result->postcode
    
    评论

报告相同问题?

悬赏问题

  • ¥15 用hfss做微带贴片阵列天线的时候分析设置有问题
  • ¥50 我撰写的python爬虫爬不了 要爬的网址有反爬机制
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥120 计算机网络的新校区组网设计
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等