Php 如何在值内获取stdClass对象的值?
我知道如何获取Php 如何在值内获取stdClass对象的值?,php,json,Php,Json,我知道如何获取net\u type的值: stdClass Object ( [net_type] => Net 1 [No of Windows] => 2 [0] => stdClass Object ( [Windows1] => stdClass Object ( [Width1] => 20 [Height1] => 10
net\u type
的值:
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
)
但是如何获得宽度1的值,即:
$details_decode = json_decode($details);
echo "details==".$details_decode->net_type;
您最好使用
json\u decode
传递第二个(true
)参数:
如果为TRUE,则返回的对象将转换为关联数组
i、 e:
然后像数组一样访问它,这会更好,因为某些对象属性中有空格。e、 g:
$details_decode = json_decode($details, true);
希望这有帮助。试试
$details\u decode[0]->Windows1->Width1
不,它不工作$details\u decode->{0'}->Windows1->Width1
你检查过这个吗?我检查过了,它不工作
$details_decode = json_decode($details, true);
$details_decode['net_type']
$details_decode[0]['Windows1']
$details_decode['Pricing/sq ft']