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.

6
  • What is the source of this data? Commented Aug 11, 2019 at 14:14
  • @NigelRen rss json from iTunes, why? Commented Aug 12, 2019 at 3:16
  • Could be worth reading stackoverflow.com/questions/4887300/… stackoverflow.com/questions/250679/… and a few others may also help. Commented Aug 12, 2019 at 5:20
  • simplexml_load_string in some cases does not capture all the details neede Commented Aug 12, 2019 at 6:04
  • I would be surrised that it misses anything and converting it to JSON can cause all sorts of problems. Commented Aug 12, 2019 at 6:12

2 Answers 2

6

Use curly brace syntax

$feed->{'im:category'}
Sign up to request clarification or add additional context in comments.

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.