Есть файл file.php Код (Text): {"icestats":{"admin":"admin[]site,"host":"site","location":"PLANETA ZEMLYA","server_id":"Icecast 2.4.0","server_start":"Thu, 08 Nov 2018 23:02:31 +0200","server_start_iso8601":"2018-11-08T23:02:31+0200","source":[{"bitrate":96,"genre":"1PVK.RU","listener_peak":0,"listeners":0,"listenurl":"http://flashnet.dn.ua:8000/rap","server_description":"Unspecified description","server_name":"Radio 1PVK","server_type":"audio/mpeg","server_url":"http://www.1pvk.ru","stream_start":"Sat, 10 Nov 2018 22:31:05 +0200","stream_start_iso8601":"2018-11-10T22:31:05+0200","title":"Nekiy Zames - Äíî(Gun Mic Studio)",,{"bitrate":128,"genre":"1PVK.RU","listener_peak":1,"listeners":0,"listenurl":"http://flashnet.dn.ua:8000/tap","server_description":"Unspecified description","server_name":"Radio 1PVK","server_type":"audio/mpeg","server_url":"http://www.1pvk.ru","stream_start":"Sat, 10 Nov 2018 20:52:05 +0200","stream_start_iso8601":"2018-11-10T20:52:05+0200","title":"Athom & Josa - Nebula (Extended Mix)",]}} Пытаюсь из него получить title Код (Text): $status = file_get_contents("file.php"); //$status = json_decode($status); $track = $status->icestats->source; echo ''.$track->title.''; Пусто, что не так пишу?
json syntax err Код (Text): $a = '{ "icestats":{ "admin":"admin[]site", "host":"site", "location":"PLANETA ZEMLYA", "server_id":"Icecast 2.4.0", "server_start":"Thu, 08 Nov 2018 23:02:31 +0200", "server_start_iso8601":"2018-11-08T23:02:31+0200", "source":[ { "bitrate":96, "genre":"1PVK.RU", "listener_peak":0, "listeners":0, "listenurl":"http://flashnet.dn.ua:8000/rap", "server_description":"Unspecified description", "server_name":"Radio 1PVK", "server_type":"audio/mpeg", "server_url":"http://www.1pvk.ru", "stream_start":"Sat, 10 Nov 2018 22:31:05 +0200", "stream_start_iso8601":"2018-11-10T22:31:05+0200", "title":"Nekiy Zames - Äíî(Gun Mic Studio)",,{ "bitrate":128, "genre":"1PVK.RU", "listener_peak":1, "listeners":0, "listenurl":"http://flashnet.dn.ua:8000/tap", "server_description":"Unspecified description", "server_name":"Radio 1PVK", "server_type":"audio/mpeg", "server_url":"http://www.1pvk.ru", "stream_start":"Sat, 10 Nov 2018 20:52:05 +0200", "stream_start_iso8601":"2018-11-10T20:52:05+0200", "title":"Athom & Josa - Nebula (Extended Mix)",]}}';
Вот сейчас правильно всё должно быть, на в ответ пустой экран( Код (Text): {"icestats":{"admin":"admin[]flashnet[]dn[]ua","host":"flashnet.dn.ua","location":"PLANETA ZEMLYA","server_id":"Icecast 2.4.0","server_start":"Thu, 08 Nov 2018 23:02:31 +0200","server_start_iso8601":"2018-11-08T23:02:31+0200","source":[{"audio_info":"bitrate=192","bitrate":192,"genre":"Various","listener_peak":1,"listeners":0,"listenurl":"http://flashnet.dn.ua:8000/mb_128","server_description":"RADIO XXI","server_name":"MUSICBOOM","server_type":"audio/mpeg","server_url":"http://musicboom.org:8000/mb_128","stream_start":"Sun, 11 Nov 2018 04:00:01 +0200","stream_start_iso8601":"2018-11-11T04:00:01+0200","title":"Tujamo - Booty Bounce","dummy":null},{"audio_info":"bitrate=256","bitrate":256,"genre":"Various","listener_peak":0,"listeners":0,"listenurl":"http://flashnet.dn.ua:8000/mb_160","server_description":"RADIO XXI","server_name":"MUSICBOOM","server_type":"audio/mpeg","server_url":"http://musicboom.org:8000/mb_160","stream_start":"Sun, 11 Nov 2018 04:00:01 +0200","stream_start_iso8601":"2018-11-11T04:00:01+0200","title":"Tujamo - Booty Bounce","dummy":null},{"audio_info":"bitrate=96","bitrate":96,"genre":"Various","listener_peak":0,"listeners":0,"listenurl":"http://flashnet.dn.ua:8000/mb_48","server_description":"RADIO XXI","server_name":"MUSICBOOM","server_type":"audio/mpeg","server_url":"http://musicboom.org:8000/mb_48","stream_start":"Sun, 11 Nov 2018 04:00:01 +0200","stream_start_iso8601":"2018-11-11T04:00:01+0200","title":"Tujamo - Booty Bounce","dummy":null},{"audio_info":"ice-samplerate=44100;ice-bitrate=192;ice-channels=2","bitrate":192,"genre":"Various","ice-bitrate":192,"ice-channels":2,"ice-samplerate":44100,"listener_peak":9,"listeners":2,"listenurl":"http://flashnet.dn.ua:8000/musicboom128","server_description":"Unspecified description","server_name":"Unspecified name","server_type":"audio/mpeg","stream_start":"Thu, 08 Nov 2018 23:02:44 +0200","stream_start_iso8601":"2018-11-08T23:02:44+0200","title":"Sick Individuals - Drive (HARDWELL EXCLUSIVE)","dummy":null},{"audio_info":"ice-samplerate=44100;ice-bitrate=256;ice-channels=2","bitrate":256,"genre":"Various","ice-bitrate":256,"ice-channels":2,"ice-samplerate":44100,"listener_peak":12,"listeners":3,"listenurl":"http://flashnet.dn.ua:8000/musicboom160","server_description":"Unspecified description","server_name":"Unspecified name","server_type":"audio/mpeg","stream_start":"Thu, 08 Nov 2018 23:02:44 +0200","stream_start_iso8601":"2018-11-08T23:02:44+0200","title":"Sick Individuals - Drive (HARDWELL EXCLUSIVE)","dummy":null},{"audio_info":"ice-samplerate=44100;ice-bitrate=96;ice-channels=2","bitrate":96,"genre":"Various","ice-bitrate":96,"ice-channels":2,"ice-samplerate":44100,"listener_peak":7,"listeners":1,"listenurl":"http://flashnet.dn.ua:8000/musicboom48","server_description":"Unspecified description","server_name":"Unspecified name","server_type":"audio/mpeg","stream_start":"Thu, 08 Nov 2018 23:02:44 +0200","stream_start_iso8601":"2018-11-08T23:02:44+0200","title":"Sick Individuals - Drive (HARDWELL EXCLUSIVE)","dummy":null},{"bitrate":96,"genre":"1PVK.RU","listener_peak":0,"listeners":0,"listenurl":"http://flashnet.dn.ua:8000/rap","server_description":"Unspecified description","server_name":"Radio 1PVK","server_type":"audio/mpeg","server_url":"http://www.1pvk.ru","stream_start":"Sun, 11 Nov 2018 19:14:40 +0200","stream_start_iso8601":"2018-11-11T19:14:40+0200","title":"Albina tea - Íå íðàâëþñü",,{"bitrate":128,"genre":"1PVK.RU","listener_peak":1,"listeners":0,"listenurl":"http://flashnet.dn.ua:8000/tap","server_description":"Unspecified description","server_name":"Radio 1PVK","server_type":"audio/mpeg","server_url":"http://www.1pvk.ru","stream_start":"Sun, 11 Nov 2018 19:14:45 +0200","stream_start_iso8601":"2018-11-11T19:14:45+0200","title":"Myo - Horurock (Sak Remix)",]}}
PHP: $jd = json_decode ( $a ); switch ( json_last_error () ) { case JSON_ERROR_NONE: echo ' - Ошибок нет'; break; case JSON_ERROR_DEPTH: echo ' - Достигнута максимальная глубина стека'; break; case JSON_ERROR_STATE_MISMATCH: echo ' - Некорректные разряды или несоответствие режимов'; break; case JSON_ERROR_CTRL_CHAR: echo ' - Некорректный управляющий символ'; break; case JSON_ERROR_SYNTAX: echo ' - Синтаксическая ошибка, некорректный JSON'; break; case JSON_ERROR_UTF8: echo ' - Некорректные символы UTF-8, возможно неверно закодирован'; break; default: echo ' - Неизвестная ошибка'; break; } print_r ( $jd );
Да я понял что ошибка в jsob. Ну тогда есть такой файл file.xsl: Код (Text): {"/tap": { "name" : "Radio 1PVK", "listeners" : "0", "description" : "Unspecified description", "title" : "Axwell & Ingrosso - More Than You Know (Older Grand Remix)", "genre" : "1PVK.RU", "url" : "http://www.1pvk.ru" } } Как в нём получить из него title при помощи php?
Код (Text): <?php $text_json = '{"/tap": { "name" : "Radio 1PVK", "listeners" : "0", "description" : "Unspecified description", "title" : "Axwell & Ingrosso - More Than You Know (Older Grand Remix)", "genre" : "1PVK.RU", "url" : "http://www.1pvk.ru" } }'; print_r(json_decode($text_json)->{"/tap"}->title); ?> Можно вот так @DJTIMOHA. Ссылочка - прям для вашего случая
Код (Text): $status = file_get_contents("http://site.ru:8000/status-json.xsl""); print_r(json_decode($status)->{"/tap"}->title); Выдаёт таймаут
PHP: $status = curlCall("http://site.ru:8000/status-json.xsl"); function curlCall($url){ $curl = curl_init($url); curl_setopt($curl, CURLOPT_HEADER, false); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); $response = curl_exec($curl); curl_close($curl); return $response; }
Ну и соответственно ссылка,к предыдущему посту @TeslaFeo. Нажимаешь на строку простой пример и получаешь все, только сам
Нет, print_r(json_decode($status)->{"/tap"}->title); Или echo, как тебе угодно, лишь бы там строка была а не массив, а то еще на полчаса
$status= curlCall("http://site.ru:8000/status-json.xsl"); Говорит о том, что ты передал все в эту переменную, с помощью функции curlCall, и данные лежат в ней; $response у тебя существует только внутри вышеописанной функции
Код (Text): $status = curlCall("http://site.ru:8000/status-json.xsl"); function curlCall($url){ $curl = curl_init($url); curl_setopt($curl, CURLOPT_HEADER, false); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); $response = curl_exec($curl); curl_close($curl); return $response; } print_r (json_decode($status)->{"/tap"}->title); Так правильно?