Проблемы с разбором объектов JSON

Мой сайт называет Spotify Web API и получает все публичные плейлисты для данного пользователя. Ответ первоначально в JSON, но мой код его декодирует.

Следующее, что я хочу сделать для кода, – отображать только объекты [external_urls] , [name] и [tracks] для каждого элемента в ответе. Для этого я пробовал это:

foreach($response_2['items'] as $item) { echo 'Link: ' . $item['external_urls'] . '<br />'; echo 'Name: ' . $item['name'] . '<br />'; echo 'Tracks: ' . $item['tracks'] . '<br />'; } 

… но это не работает должным образом. Все [name] -объекты (которые являются строкой ) правильно повторяются, но для всех [external_urls] и [tracks] (которые являются объектами ) он только говорит «Массив» в браузере.

Думаю, я должен использовать print_r () для этих объектов, но я не могу заставить его работать.

Какие-либо предложения?

Мой код:

 <?php $url = 'https://accounts.spotify.com/api/token'; $method = 'POST'; $credentials = "hidden:hidden"; $headers = array( "Accept: */*", "Content-Type: application/x-www-form-urlencoded", "Authorization: Basic " . base64_encode($credentials)); $data = 'grant_type=client_credentials'; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $data); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $response_1 = curl_exec($ch); curl_close($ch); $response_1 = json_decode($response_1, true); $token = $response_1['access_token']; $headers_2 = array( "Accept: */*", "Content-Type: application/x-www-form-urlencoded", ('Authorization: Bearer ' . $token)); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL,'https://api.spotify.com/v1/users/wizzler/playlists'); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers_2); curl_setopt($ch, CURLOPT_POST, false); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $response_2 = curl_exec($ch); curl_close($ch); $response_2 = json_decode($response_2, true); ?> 

API-ответ:

 { "href": "https://api.spotify.com/v1/users/wizzler/playlists", "items": [ { "collaborative": false, "external_urls": { "spotify": "http://open.spotify.com/user/wizzler/playlists/53Y8wT46QIMz5H4WQ8O22c" }, "href": "https://api.spotify.com/v1/users/wizzler/playlists/53Y8wT46QIMz5H4WQ8O22c", "id": "53Y8wT46QIMz5H4WQ8O22c", "name": "Wizzlers Big Playlist", "owner": { "external_urls": { "spotify": "http://open.spotify.com/user/wizzler" }, "href": "https://api.spotify.com/v1/users/wizzler", "id": "wizzler", "type": "user", "uri": "spotify:user:wizzler" }, "public": true, "tracks": { "href": "https://api.spotify.com/v1/users/wizzler/playlists/53Y8wT46QIMz5H4WQ8O22c/tracks", "total": 30 }, "type": "playlist", "uri": "spotify:user:wizzler:playlist:53Y8wT46QIMz5H4WQ8O22c" }, { "collaborative": false, "external_urls": { "spotify": "http://open.spotify.com/user/wizzlersmate/playlists/1AVZz0mBuGbCEoNRQdYQju" }, "href": "https://api.spotify.com/v1/users/wizzlersmate/playlists/1AVZz0mBuGbCEoNRQdYQju", "id": "1AVZz0mBuGbCEoNRQdYQju", "name": "Another Playlist", "owner": { "external_urls": { "spotify": "http://open.spotify.com/user/wizzlersmate" }, "href": "https://api.spotify.com/v1/users/wizzlersmate", "id": "wizzlersmate", "type": "user", "uri": "spotify:user:wizzlersmate" }, "public": true, "tracks": { "href": "https://api.spotify.com/v1/users/wizzlersmate/playlists/1AVZz0mBuGbCEoNRQdYQju/tracks", "total": 58 }, "type": "playlist", "uri": "spotify:user:wizzlersmate:playlist:1AVZz0mBuGbCEoNRQdYQju"... } ], "limit": 9, "next": null, "offset": 0, "previous": null, "total": 9 }