简体   繁体   English

如何获取内部值的stdClass对象的值?

[英]How to fetch value of stdClass Object inside value?

stdClass Object
(
   [net_type] => Net 1
   [No of Windows] => 2
   [0] => stdClass Object
    (
        [Windows1] => stdClass Object
            (
                [Width1] => 20
                [Height1] => 10
            )

        [Windows2] => stdClass Object
            (
                [Width2] => 40
                [Height2] => 15
            )

    )

   [Pricing/sq ft] => 20
   [Total Area] => 2
   [Total Price] => 5
)

I know to get value of net_type : 我知道要获得net_type价值:

$details_decode = json_decode($details);
echo "details==".$details_decode->net_type;

But how to get value of Width1 ie: 但是如何获得Width1值,即:

echo "windows 1==".$details_decode->Windows1['Width1'];

You are probably best to pass a second ( true ) parameter with json_decode : 您最好是使用json_decode传递第二个( true )参数:

When TRUE, returned objects will be converted into associative arrays. 如果为TRUE,则返回的对象将转换为关联数组。

ie: 即:

$details_decode = json_decode($details, true);

And then access it like an array, this is better since some of the object properties have spaces in them. 然后像数组一样访问它,这样做会更好,因为某些对象属性中包含空格。 eg: 例如:

$details_decode['net_type']
$details_decode[0]['Windows1']
$details_decode['Pricing/sq ft']

Hope this helps. 希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM