如何访问已解码JSON的下层元素?

时间:2015-05-16 01:56:57

标签: php json decode

我可以访问yyyy没问题。

$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 个答案:

答案 0 :(得分:1)

我会把它作为一个数组拉出然后访问它。请注意,无论如何,这是非常复杂的。如果你能

,我会考虑简化你的JSON
Error: php56-pdo conflicts with php-pdo-5.3.29-1.8.amzn1.x86_64
Error: httpd24-tools conflicts with httpd-tools-2.2.29-1.5.amzn1.x86_64
Error: php56-common conflicts with php-common-5.3.29-1.8.amzn1.x86_64
Error: httpd24 conflicts with httpd-2.2.29-1.5.amzn1.x86_64
Error: php56-process conflicts with php-process-5.3.29-1.8.amzn1.x86_64
Error: php56 conflicts with php-5.3.29-1.8.amzn1.x86_64
Error: php56-xml conflicts with php-xml-5.3.29-1.8.amzn1.x86_64
Error: php56-cli conflicts with php-cli-5.3.29-1.8.amzn1.x86_64
Error: php-mysql conflicts with php56-mysqlnd-5.6.8-1.111.amzn1.x86_64

如果你真的想要对象方式

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