简体   繁体   中英

Trying to get property 'id' of non-object {"exception":"[object]

我有一个 $data= [{"id":54,"systemid":"1610000060000000063"}]并且我试图获得这样的 id $id = $data['id']甚至我试过$data->id和我正在尝试获取非对象的属性 'id' {"exception":"[object] (ErrorException(code: 0): Trying to get property 'id' of non-object)

you have an array in json format:

 $array='[{"id":54,"systemid":"1610000060000000063"}]';

first you have to decode the array:

$decodedArray=json_decode($array);

then get the element at index 0:

$object=$decodedArray[0];

then you can get it's id:

$id=$object->id;

see the sandbox for it:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM