2015-05-16 28 views
-2

我可以訪問yyyy沒問題。如何訪問已解碼JSON的較低元素?

$json = file_get_contents("JSON.TXT"); 
$array = json_decode($json); 

debug_print("yyyy=" . $array->xxxx->yyyy. PHP_EOL) ; 

但是,如何訪問eeee

stdClass Object 
(
    [xxxx] => stdClass Object 
     (
      [yyyy] => r 
      [zzzz] => Array 
       (
        [0] => stdClass Object 
         (
          [aaaa] => 01  
          [bbbb] => Array 
           (
            [0] => stdClass Object 
             (
              [cccc_id] => 1 
              [dddd] => Array 
               (
                [0] => stdClass Object 
                 (
                  [eeee] => 1 

回答

1

我會把它拉出來作爲一個數組,然後訪問它。不管怎樣,請注意這一點非常複雜。我會考慮簡化您的JSON,如果你能

$array = json_decode($json, true); 
echo $array['xxxx']['zzzz'][0]['bbbb'][0]['dddd'][0]['eeee']; 

如果你真的想要的對象的方式

echo $array->xxxx->zzzz[0]->bbbb[0]->dddd[0]->eeee; 
+0

我還是想知道如何訪問它的其他方式。謝謝。 – TheRumpledOne

+0

添加了對象的方式 – Machavity

+0

謝謝Machavity,抽空回答我的問題。我感謝你的好意。 – TheRumpledOne