Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/296.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何在值内获取stdClass对象的值?_Php_Json - Fatal编程技术网

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']