【问题标题】:How to access/output this json_decode multi dimensional associative array with PHP如何使用 PHP 访问/输出这个 json_decode 多维关联数组
【发布时间】:2011-09-13 19:44:21
【问题描述】:

我正在尝试访问和输出 JSON 响应:

  1. 我想获取 Web 数组中 [Start]=>0 的值。

  2. 我还需要遍历并输出[results][0]clickurl,title等。

    我已经花了几个小时尝试所有类型的组合,但都无济于事。感谢您的帮助!

      Array
        (
    [bossresponse] => Array
        (
            [responsecode] => 200
            [web] => Array
                (
                    [start] => 0
                    [count] => 14
                    [totalresults] => 14
                    [results] => Array
                        (
                            [0] => Array
                                (
                                    [date] => 
                                    [clickurl] => http://url.com/1
                                    [url] => http://url.com/1
                                    [dispurl] => http://url.com/1...
                                    [title] => Title of Content 1
                                    [abstract] => This is the summary, This is the summary,    This is the summary, ...
                                )
    
                            [1] => Array
                                (
                                    [date] => 
                                    [clickurl] => http://url.com/2
                                    [url] => http://url.com/2
                                    [dispurl] => http://url.com/2...
                                    [title] => Title of Content 2
                                    [abstract] => This is the summary, This is the summary,  This is the summary, ...
                                )
                        )
    
                  )
    
           )
    
    )
    

【问题讨论】:

    标签: php arrays json


    【解决方案1】:
    echo $var['bossresponse']['web']['start'];
    foreach ($var['bossresponse']['web']['results'] as $result) 
      foreach ($result as $key => $value) {
        echo "$key => $value <br>";
      }
    }    
    

    【讨论】:

    • 你能在下面看到我的评论,让我知道发生了什么吗?
    【解决方案2】:
    $json['bossresponse']['web']['start']
    $json['bossresponse']['web']['results'][0]['title']
    

    在foreach()中

    foreach($json['bossresponse']['web']['results'] as $j){
         echo "<br>title".$j['title'];
    }
    

    【讨论】:

    • 谢谢你,我正在使用它,但我试图在 foreach 中这样做。
    猜你喜欢
    • 2018-07-05
    • 2017-04-28
    • 2013-02-02
    • 2013-01-07
    • 2014-07-19
    • 1970-01-01
    • 2015-07-16
    • 1970-01-01
    • 2013-05-22
    相关资源
    最近更新 更多