【发布时间】:2011-08-18 01:28:31
【问题描述】:
我有一个 stdclass 对象,如下所示:
stdClass Object
(
[text] => Parent
[values] => Array
(
[0] => stdClass Object
(
[id] => /m/0c02911
[text] => Laurence W. Lane Jr.
[url] => http://www.freebase.com/view/m/0c02911
)
)
)
我迭代了多个这样的对象,其中一些具有
stdClass Object
(
[text] => Named after
[values] => Array
(
[0] => stdClass Object
(
[id] => /m/0c02911
[text] => Stanford
[url] => SomeURL
)
)
)
我想知道如果“值”对象出现在以“父”为值的“文本”之后,我将如何访问它?
【问题讨论】:
-
你有没有尝试过类似 Object['text']['values'][0]['id'] 的东西,这是相当深的数组;)
-
问题是它会返回文本值为“Named after”的对象,而我只想要文本值为“Parent”的对象。谢谢!
-
在你的循环中做一个检查 if(Object['text'] === 'Parent') echo 'Found parent'
-
我不确定您使用什么语言进行迭代,但在 PHP 中,它是
$object->values[0]->id。 编辑:哦,“值”不是一个对象,而是一个对象属性。 -
还有@robx 我如何访问下一个值?因为对象不是Object['text']['values'],而是Object['values']
标签: php arrays json curl stdclass