Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我如何读取这个数组?
stdClass Object ( [0] => stdClass Object ( [role_id] => 1 [username] => me@gmail.com [date_time] => 2013-01-13 14:01:00 ) [status] => success )
我可以将状态读取为 $objectname->status,但我无法读取 $objectname->username。
那是因为username是 的一个属性$objectname->{"0"},它也是一个对象。
username
$objectname->{"0"}
试试这个:
$json='{"0":{"role_id":1,"username":"me@gmail.com","date_time":"2013-01-13 14:01:00"},"status":"success"}'; $obj=json_decode($json); var_dump($obj); var_dump($obj->{"0"}->username);
活生生的例子