如何使用PHP访问/输出这个json_decode多维关联数组

时间:2011-09-13 19:44:22

标签: php arrays json

我正在尝试访问并输出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, ...
                                )
                        )
    
                  )
    
           )
    
    )
    

2 个答案:

答案 0 :(得分:0)

$json['bossresponse']['web']['start']
$json['bossresponse']['web']['results'][0]['title']
在foreach()中

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

答案 1 :(得分:0)

echo $var['bossresponse']['web']['start'];
foreach ($var['bossresponse']['web']['results'] as $result) 
  foreach ($result as $key => $value) {
    echo "$key => $value <br>";
  }
}