使用key的名称从数组中获取值

时间:2012-11-21 06:40:06

标签: arrays

我有下面提到的编码。我想从这个数组中获取response_text和response_code的值。任何人都可以帮助我获取特定的键值。

stdClass Object
(
    [_OPS_version] => 0.9
    [protocol] => XCP
    [request_response_time] => 0.441
    [response_text] => Command completed successfully
    [is_search_completed] => 1
    [action] => REPLY
    [attributes] => stdClass Object
        (
            [suggestion] => stdClass Object
                (
                    [count] => 0
                    [response_text] => Missing tld list, supported tlds are [.com,.net,.org,.info,.biz,.us,.mobi]
                    [response_code] => 500
                    [is_success] => 0
                )

        )

    [response_code] => 200
    [is_success] => 1
)

提前致谢

2 个答案:

答案 0 :(得分:0)

使用命名空间System.Reflection,尝试使用PropertyInfo [] info = stdClass.GetProperies(),然后遍历每个属性并检查调试模式下的值。

答案 1 :(得分:0)

在php中,我们可以获取如下所述的值

$检查= $结果 - > { '属性'} - > suggestion-> response_text;

参考:http://bytes.com/topic/php/answers/161452-stdclass-object-get_object_vars