0

I am trying to decode some data from a json file, and i can't seem to get any of the relevant data. When i echo any of the data, it is just blank.

I am trying to get the following data from the below json file

now_playing > song > text

now_playing > song > art

and then do a foreach for the song_history

song_history > text

song_history > text > art

{
    "station": {
        "id": 1,
        "name": "Radio Quarantine",
        "shortcode": "radio_quarantine",
        "description": "",
        "frontend": "icecast",
        "backend": "liquidsoap",
        "listen_url": "XXX",
        "url": "",
        "public_player_url": "XXX",
        "is_public": false,
            "path": "/radio.mp3",
            "is_default": true,
            "id": 1,
            "name": "128kbps MP3",
            "url": "XXX",
            "bitrate": 128,
            "format": "mp3",
            "listeners": {
                "total": 0,
                "unique": 0,
                "current": 0
            }
        }],
        "remotes": []
    },
    "listeners": {
        "total": 0,
        "unique": 0,
        "current": 0
    },
    "live": {
        "is_live": false,
        "streamer_name": "",
        "broadcast_start": null
    },
    "now_playing": {
        "elapsed": 168,
        "remaining": 80,
        "sh_id": 375,
        "played_at": 1632861349,
        "duration": 248,
        "playlist": "Alternative",
        "streamer": "",
        "is_request": false,
        "song": {
            "id": "c817feb1bf4d7e96ead5140b7339b2a5",
            "text": "Nothing But Thieves - Impossible",
            "artist": "Nothing But Thieves",
            "title": "Impossible",
            "album": "Moral Panic",
            "genre": "",
            "lyrics": "",
            "art": "XXX",
            "custom_fields": []
        }
    },
    "playing_next": {
        "cued_at": 1632861547,
        "duration": 225,
        "playlist": "Alternative",
        "is_request": false,
        "song": {
            "id": "d0df77d1f8c0e22fab9ed736283b55a1",
            "text": "Feeder - Just a Day - Edit",
            "artist": "Feeder",
            "title": "Just a Day - Edit",
            "album": "The Singles",
            "genre": "",
            "lyrics": "",
            "art": "xxx",
            "custom_fields": []
        }
    },
    "song_history": [{
            "sh_id": 374,
            "played_at": 1632861108,
            "duration": 245,
            "playlist": "Alternative",
            "streamer": "",
            "is_request": false,
            "song": {
                "id": "34e78efdb4605e113b633db819ade2dd",
                "text": "Cornershop - Brimful of Asha",
                "artist": "Cornershop",
                "title": "Brimful of Asha",
                "album": "Brimful of Asha",
                "genre": "",
                "lyrics": "",
                "art": "xxx",
                "custom_fields": []
            }
        },
        {
            "sh_id": 373,
            "played_at": 1632860868,
            "duration": 242,
            "playlist": "Alternative",
            "streamer": "",
            "is_request": false,
            "song": {
                "id": "1b5ae81131d689e1f50017be91c4be9f",
                "text": "Foals - Mountain at My Gates",
                "artist": "Foals",
                "title": "Mountain at My Gates",
                "album": "What Went Down",
                "genre": "",
                "lyrics": "",
                "art": "https://stream.radioquarantine.co.uk/api/station/1/art/5a1b082f55834d20627d527f-1632826099.jpg",
                "custom_fields": []
            }
        },
        {
            "sh_id": 372,
            "played_at": 1632860674,
            "duration": 196,
            "playlist": "Alternative",
            "streamer": "",
            "is_request": false,
            "song": {
                "id": "ca395c70d0666cabdada7b0013ca7ffb",
                "text": "The Vaccines - Alone Star",
                "artist": "The Vaccines",
                "title": "Alone Star",
                "album": "Back In Love City",
                "genre": "",
                "lyrics": "",
                "art": "https://stream.radioquarantine.co.uk/api/station/1/art/c89b14e1abd7ce8dafd2ed8a-1632847127.jpg",
                "custom_fields": []
            }
        },
        {
            "sh_id": 371,
            "played_at": 1632860497,
            "duration": 180,
            "playlist": "Alternative",
            "streamer": "",
            "is_request": false,
            "song": {
                "id": "4ccd55a7cd6a091e7f7d95e7817a680f",
                "text": "Fall Out Boy - Dance, Dance",
                "artist": "Fall Out Boy",
                "title": "Dance, Dance",
                "album": "From Under The Cork Tree",
                "genre": "",
                "lyrics": "",
                "art": "xxx",
                "custom_fields": []
            }
        },
        {
            "sh_id": 370,
            "played_at": 1632860265,
            "duration": 232,
            "playlist": "Alternative",
            "streamer": "",
            "is_request": false,
            "song": {
                "id": "3a36e54b613b0c2f46e2acbcc6ebb9e8",
                "text": "The White Stripes - Seven Nation Army",
                "artist": "The White Stripes",
                "title": "Seven Nation Army",
                "album": "Elephant",
                "genre": "",
                "lyrics": "",
                "art": "xxxx",
                "custom_fields": []
            }
        }
    ],
    "is_online": true,
    "cache": "event"
}

I tried the following :

$data = file_get_contents('URL TO JSON');
$data = json_decode($data,true);
echo $data->now_playing['text'];
Barmar
  • 741,623
  • 53
  • 500
  • 612

0 Answers0