dongqijuan3786
2014-12-22 06:23
浏览 60
已采纳

使用PHP循环访问JSON数组

My Code:

$json2 = json_decode($content, true);
$thing = $json2{"reply1"}->{"tokens"};
foreach ($thing as $laa) {
  echo $laa->token;
}

Whenever I run this code against my JSON it returns:

PHP Notice:  Trying to get property of non-object in /root/backup.php on line 33
PHP Warning:  Invalid argument supplied for foreach() in /root/backup.php

All I want to do is loop through the JSON and get one part which is the token for each [token]. (Starting part of JSON)

JSON:

Array
(
    [errors] => Array
        (
        )

    [reply] => success
    [item] => Array
        (
            [status] => CURRENT
            [messageURI] => 
        )

    [reply1] => Array
        (
            [tokens] => Array
                (
                    [0] => Array
                        (
                            [token] => 123456

                        )

                    [1] => Array
                        (
                            [token] => 123456

                                )

Any help is appreciated. Thanks.

1条回答 默认 最新

相关推荐 更多相似问题