Php 使用JSON的Shoutcast统计

Php 使用JSON的Shoutcast统计,php,json,shoutcast,Php,Json,Shoutcast,这可能是一个非常简单的答案,但我一直在尝试各种变化,以从shoutcast数据中提取当前歌曲/艺术家。我的代码是: $str = file_get_contents('https://radio.siteurl.com/api/nowplaying/1/'); $json = json_decode($str, true); // decode the JSON into an associative array $listeners = $json['listeners']; $streame

这可能是一个非常简单的答案,但我一直在尝试各种变化,以从shoutcast数据中提取当前歌曲/艺术家。我的代码是:

$str = file_get_contents('https://radio.siteurl.com/api/nowplaying/1/');
$json = json_decode($str, true); // decode the JSON into an associative array
$listeners = $json['listeners'];
$streamer = $json['live']['streamer_name'];
听众和流媒体姓名信息都能通过,但我无法让当前的歌曲和艺术家通过

我试过下面的变化,但这些似乎并没有解决任何问题

  Attempt 1. $current =  $json['live']['song']['now_playing']['text'];
Attempt 2. $current =  $json['song']['text'];
Attempt 3. $current =  $json['live']['now_playing']['text'];
Attempt 4. $current =  $json['now_playing']['text'];
JSON


您所需要做的就是按照您需要的元素的路径进行操作,例如:

echo $json['now_playing']['song']['text']; //output: Kylie Minogue - Every Days Like Christmas
echo $json['now_playing']['song']['artist']; //output:Kylie Minogue

您可以使用
print\u r()
var\u dump()
来更好地查看数据路径。

如果您不将json放在问题主体中,没有人能够猜到。确实@YvesLeBorg现在为您添加了以下内容:)
echo $json['now_playing']['song']['text']; //output: Kylie Minogue - Every Days Like Christmas
echo $json['now_playing']['song']['artist']; //output:Kylie Minogue