如何在特定键值对后访问 stdclass 对象? [英] How to access stdclass object after a specific key value pair?

查看:28
本文介绍了如何在特定键值对后访问 stdclass 对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 stdclass 对象,如下所示:

I have a stdclass object as shown below:

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
                )

        )

)

我迭代了多个这样的对象,其中一些有

I iterate over multiple such objects, some of which have

stdClass Object
(
    [text] => Named after
    [values] => Array
        (
            [0] => stdClass Object
                (
                    [id] => /m/0c02911
                    [text] => Stanford
                    [url] => SomeURL
                )

        )

)

我想知道如果值"对象出现在以父级"作为其值的文本"之后,我将如何访问它?

I was wondering how I would access the "values" object if it comes after a "text" that has "Parent" as its value?

推荐答案

您要找的是 Object['values'][0]: 'values' 是 keymap,就像 'text',而 [0]是您希望访问的数组内的索引.因此,如果您想将 id 深入到巢中,则必须执行类似

What you are looking for is the Object['values'][0]: 'values' is the keymap just like 'text', and [0] is the index inside that array you wish to access. so if you would like to get the id deep in the nest, you'd have to do something like

Object['values'][0]['id']

Object['values'][0]->id

应该给你/m/0c02911.但是我不知道您是如何进行循环的,因此您必须根据需要对其进行调整,并将适当的变量放置在循环中该代码中需要放入的位置.不确定您使用的是哪种语言.

which should give you /m/0c02911. But I have no idea how you are doing your loop, so you will have to adjust it to your needs and place proper variables where they need to go in that code in your loop. Not exactly sure which language you are working with.

这篇关于如何在特定键值对后访问 stdclass 对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆