Creating foreach loop through JSON numerically indexed stdclass objects

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP

Creating foreach loop through JSON numerically indexed stdclass objects



I am trying to get data from the musixmatch api, have managed to connect with success but am struggling to print a value from a numerically indexed stdclass object



here is one result from my json:





"message":
"header":
"status_code": 200,
"execute_time": 0.016516923904419,
"available": 685
,
"body":
"track_list": [

"track":
"track_id": 13799336,
"track_mbid": "cc72094f-baa3-4017-b628-d95bf1087144",
"track_isrc": "",
"track_spotify_id": "",
"track_soundcloud_id": "",
"track_xboxmusic_id": "",
"track_name": "Accents",
"track_name_translation_list": [

],
"track_rating": 1,
"track_length": 238,
"commontrack_id": 9433434,
"instrumental": 0,
"explicit": 0,
"has_lyrics": 0,
"has_lyrics_crowd": 0,
"has_subtitles": 0,
"has_richsync": 0,
"num_favourite": 0,
"lyrics_id": 0,
"subtitle_id": 0,
"album_id": 13799348,
"album_name": "X-Posed: The Interview",
"artist_id": 33491916,
"artist_mbid": "e0140a67-e4d1-4f13-8a01-364355bee46e",
"artist_name": "Justin Bieber",
"album_coverart_100x100": "http://s.mxmcdn.net/images-storage/albums/nocover.png",
"album_coverart_350x350": "",
"album_coverart_500x500": "",
"album_coverart_800x800": "",
"track_share_url": "https://www.musixmatch.com/lyrics/Justin-Bieber/Accents?utm_source=application&utm_campaign=api&utm_medium=Song+Find%3A1409613795717",
"track_edit_url": "https://www.musixmatch.com/lyrics/Justin-Bieber/Accents/edit?utm_source=application&utm_campaign=api&utm_medium=Song+Find%3A1409613795717",
"commontrack_vanity_id": "Justin-Bieber/Accents",
"restricted": 0,
"first_release_date": "2011-04-05T00:00:00Z",
"updated_time": "2017-04-28T14:06:57Z",
"primary_genres":
"music_genre_list": [

]
,
"secondary_genres":
"music_genre_list": [

]



]




And here is my attempt at getting the track_name




$url = file_get_contents("http://api.musixmatch.com/ws/1.1/track.search?q_artist=justin%20bieber&apikey=MYAPIKEY");
$json = json_decode($url);

foreach($json->message->body->track_list->track as $track)
echo $track->track_name;







The code above doesnt print anything but if I do




$tracks = $json->message->body->track_list['0']->track->track_name;



It will print the track name, but of course I would like to print all the track_name values from each track in the list



Any help appreciated









By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Comments

Popular posts from this blog

Executable numpy error

Trying to Print Gridster Items to PDF without overlapping contents

Hystrix command on request collapser fallback