-3

私はjsonデコードを使用してこのデータを取得したい。助けてください..

これまでのところ、このスクリプトを思いつきましたが、アクションの下で最後から2番目と最後の「名前」と「リンク」を取得できません。助けてください..

foreach($json['data'] as $post)
{
$name1 = $post['actions']['name'];
$name2 = $post['actions']['name']['name'];
$name3 = $post['actions']['name']['name']['name'];

しかし、これは機能していません。次の例からすべての名前とリンクデータを取得したいのですが、Facebook グラフ API のスニペットです。

    {
      "data": [
        {

          "actions": [
            {
              "name": "Comment", 
              "link": "http://www.facebook.com/xxxxxidxxxx/posts/xxxxidxxxxxx"
            }, 
            {
              "name": "Like", 
              "link": "http://www.facebook.com/xxxxxidxxxxxx/posts/xxxxidxxxxxxx"
            }
{
              "name": "Comment", 
              "link": "http://www.facebook.com/xxxxxidxxxx/posts/xxxxidxxxxxx"
            }, 
            {
              "name": "Like", 
              "link": "http://www.facebook.com/xxxxxidxxxxxx/posts/xxxxidxxxxxxx"
            }
{
              "name": "Comment", 
              "link": "http://www.facebook.com/xxxxxidxxxx/posts/xxxxidxxxxxx"
            }, 
            {
              "name": "Like", 
              "link": "http://www.facebook.com/xxxxxidxxxxxx/posts/xxxxidxxxxxxx"
            }
          ],
4

1 に答える 1

0

actionsこれは配列であり、この場合の唯一のメンバーであることに注意してくださいdata

間違った部分を繰り返すだけで、コードは次のようになります。

foreach($json['data']['actions'] as $action) {
  $name = $action['name'];
  $link = $action['link'];
}
于 2012-06-29T19:34:33.030 に答える