1

i have a $data= [{"id":54,"systemid":"1610000060000000063"}]and i am trying to get id like this $id = $data['id'] and even i tried $data->id and i am getting Trying to get property 'id' of non-object {"exception":"[object] (ErrorException(code: 0): Trying to get property 'id' of non-object)

Ostaad g
  • 301
  • 1
  • 7
  • 4
    Does this answer your question? [How to convert JSON string to array](https://stackoverflow.com/questions/7511821/how-to-convert-json-string-to-array) – Rain Nov 06 '21 at 11:41

1 Answers1

2

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:

STA
  • 30,729
  • 8
  • 45
  • 59
OMR
  • 11,736
  • 5
  • 20
  • 35