从std Object获取价值

时间:2012-03-06 08:09:05

标签: php facebook-graph-api

任何人都可以帮助我解决这个问题:我试图用$someVar->data->values->value来回应“价值”的价值,但不回报任何东西。我也试过了$someVar->values->value。我是一个PHP新手所以请原谅我,如果这是一个愚蠢的问题。

 stdClass Object ( [data] => Array ( [0] => stdClass Object ( [id] => 
123/insights/post_impressions_organic_unique/lifetime [name] => 
post_impressions_organic_unique [period] => lifetime [values] => Array ( [0] => 
stdClass Object ( [value] => 286 ) ) [title] => Lifetime Post Organic Reach [description] => Lifetime The number of people who saw your Page post in News Feed or ticker, or on your Page's Wall. (Unique Users) ) ) [paging] => stdClass Object ( [previous] => 
https://graph.facebook.com/123/insights/post_impressions_organic_unique&access_token=[next] => https://graph.facebook.com/123/insights/post_impressions_organic_unique&access_token= ) )

代码是来自Facebook Graph API的JSON解码输出。

2 个答案:

答案 0 :(得分:3)

对象中有数组,试试这个。

foreach($someVar->data as $arr1)
{
    foreach($arr1->values as $obj)
    {
        echo 'Value: ' . $obj->value;
    }
}

如果您在打印对象周围放置<pre>标签,它会对您进行格式化,这样您就可以轻松查看结构。

答案 1 :(得分:0)

$someVar->data[0]->values[0]->value