doufu1950 2016-05-04 20:26
浏览 15

多维数组无法打印值

I have a multidimensional array coming from JSON. I cannot seem to get to print one value from all. It either gives me nothing or says array. I need to print all the zip_code fields.

 $spit = json_decode($result);

Yields:

stdClass Object
   (
  [zip_codes] => Array
    (
        [0] => stdClass Object
            (
                [zip_code] => 33779
                [distance] => 9.513
                [city] => Largo
                [state] => FL
            )

        [1] => stdClass Object
            (
                [zip_code] => 33771
                [distance] => 9.188
                [city] => Largo
                [state] => FL
            )

        [2] => stdClass Object
            (
                [zip_code] => 33760
                [distance] => 9.989
                [city] => Clearwater
                [state] => FL
            )

        [3] => stdClass Object
            (
                [zip_code] => 33770
                [distance] => 8.525
                [city] => Largo
                [state] => FL
            )

        [4] => stdClass Object
            (
                [zip_code] => 33786
                [distance] => 8.153
                [city] => Belleair Beach
                [state] => FL
            )

        [5] => stdClass Object
            (
                [zip_code] => 33764
                [distance] => 7.651
                [city] => Clearwater
                [state] => FL
            )

        [6] => stdClass Object
            (
                [zip_code] => 33756
                [distance] => 6.373
                [city] => Clearwater
                [state] => FL
            )

I have tried to access with $zip=$spit->zip_codes->zip_code; and $zip=['zip_codes']['zip_code'];

I am sure I am just missing the obvious but have tried about 20 ways to echo it out with no luck.

  • 写回答

1条回答 默认 最新

  • douhuan1905 2016-05-05 09:53
    关注

    Change

    $spit = json_decode($result);
    

    to

    $spit = json_decode($result,1);
    

    This will convert JSON into an array and then you can print the zip code as

    print_r($spit["zip_codes"]);
    
    评论

报告相同问题?

悬赏问题

  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测