3

I need to access the value of a variable element in Json, the problem however the variable has a colon (:) and i keep getting undefined variable every time.

{#370 ▼
  +"im:name": {#371 ▶}
  +"im:image": array:3 [▶]
  +"im:itemCount": {#380 ▶}
  +"im:price": {#381 ▶}
  +"im:contentType": {#385 ▶}
  +"rights": {#387 ▶}
  +"title": {#388 ▶}
  +"link": {#390 ▶}
  +"id": {#391 ▶}
  +"im:artist": {#393 ▶}
  +"category": {#396 ▶}
  +"im:releaseDate": {#397 ▶}
}

for example $feed->category is okay , but anything with : in between like $feed->im:category throws an error.

aynber
  • 22,380
  • 8
  • 50
  • 63
TechPotter
  • 579
  • 8
  • 14

2 Answers2

6

Use curly brace syntax

$feed->{'im:category'}
Dharman
  • 30,962
  • 25
  • 85
  • 135
0

Try to json_decode it and force the use of associative arrays with JSON_OBJECT_AS_ARRAY.

Dharman
  • 30,962
  • 25
  • 85
  • 135
KHALDOUN
  • 627
  • 5
  • 2