0

I have already search here but can't finde any questions regrading this actually problem.

i got this code which is working until i have to phase the "lock.status" because of the "." the code fails and the json is coming from another site so i can't change it to be "_" or something else. So how can i use "." in this code?

$jsonObject = json_decode($result);
foreach ($jsonObject->result as $data) {
    echo $data->lock.status;
}
RiggsFolly
  • 93,638
  • 21
  • 103
  • 149
Jonas
  • 1
  • 1
    Alternative to the answer below is adding `true` to the 2nd param of `json_decode()`, e.g `json_decode($result, true)` which will return an array instead of an object. Then you can access the value by `$data['lock.status']` which looks nicer in my opinion. – GrumpyCrouton Dec 16 '21 at 18:55

1 Answers1

4

You can use {} to allow you to use a string as an object key.

echo $data->{'lock.status'};
gen_Eric
  • 223,194
  • 41
  • 299
  • 337