如何为特定键值对后进入stdClass的对象吗? [英] How to access stdclass object after a specific key value pair?

查看:118
本文介绍了如何为特定键值对后进入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 ['值'] [0]:'值'是键盘布局就像'文字',和[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。但是,我不知道你是怎么做的循环,所以你必须把它调整到您的需求,并把正确的变量,他们需要在你的循环,code去。不清楚自己正在使用的语言。

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天全站免登陆