[英]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
)
我知道要获得net_type
价值:
$details_decode = json_decode($details);
echo "details==".$details_decode->net_type;
但是如何获得Width1
值,即:
echo "windows 1==".$details_decode->Windows1['Width1'];
您最好是使用json_decode
传递第二个( true
)参数:
如果为TRUE,则返回的对象将转换为关联数组。
即:
$details_decode = json_decode($details, true);
然后像数组一样访问它,这样做会更好,因为某些对象属性中包含空格。 例如:
$details_decode['net_type']
$details_decode[0]['Windows1']
$details_decode['Pricing/sq ft']
希望这可以帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.