【发布时间】:2013-04-07 04:56:07
【问题描述】:
我正在使用 Twitter API(1.1 版)并试图通过 PHP 从 JSON 返回中获取特定变量。 $mentions 是 GET statuses/mentions_timeline 请求返回的 json_decode() 值。
我有以下 PHP:
foreach($mentions as $mention) {
echo '<pre>' . print_r($mention) . "</pre><br>";
}
这按预期工作,但是当我将 ['created_at'] 添加到 $mention 时,我得到:
Fatal error: Cannot use object of type stdClass as array
根据twitter docs的预期回报:
[ // mentions
{ // mention
"created_at": "Mon Sep 03 13:24:14 +0000 2012"
}
]
这是 print_r($mention)(在循环内)返回的示例:
stdClass Object (
[created_at] => Sat Apr 06 14:56:36 +0000 2013
)
这个 stdClass 是什么?如果可能的话,我该如何与之交互?
【问题讨论】: