dongzhong1891
2018-03-13 08:07
浏览 51

如何在PHP中读取JSON对象

This is my JSON object:

<pre>
stdClass Object
(
[user] => stdClass Object
    (
        [name] => Bob Smith
        [age] => 47
    )

[0] => CEO
[1] => USA
)
</pre>

How to read these last two output:

[0] => CEO<br/>
[1] => USA<br/>

like I am reading this:

<pre>
$res = json_decode($json_data);
echo $res->user->name; //out : Bob Smith
</pre>
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • doushuo8677 2018-03-13 08:49
    已采纳

    For reading that indexes you have to:

    echo $res->{"0"};
    

    Using [ ] brackets will threat it as an array, and you cannot -> directly a number

    已采纳该答案
    打赏 评论

相关推荐 更多相似问题