簡體   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
)

我知道要獲得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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM