2017-08-17 265 views
0

我需要從這裏https://use.gameapis.net/mc/query/info/play.mineverge.net獲取JSON數據

獲取JSON數據,我需要的「在線」:126在我的網頁顯示。

"players": { 
    "online": 126, 
    "max": 500 

這裏是我目前的代碼,(不工作),以獲得JSON。難道我做錯了什麼?它顯示一切不僅僅是 「在線」:

   $playeronline = file_get_contents ('https://use.gameapis.net/mc/query/info/' . $server); 
      echo $playeronline->players[1]; 
      echo $playeronline['online']; 

回答

1

這爲我工作,我測試了它:

$str = file_get_contents ('https://use.gameapis.net/mc/query/info/play.mineverge.net'); 

$playersonline = json_decode($str); 

echo $playersonline->players->online; 
0

如前所述here你需要使用json_decode功能如下:

$playeronline = file_get_contents('https://use.gameapis.net/mc/query/info/' . $server); 

$obj = json_decode($playeronline); 
echo $playersonline->players->online; 
1

試試這個,

$playeronline = file_get_contents ('https://use.gameapis.net/mc/query/info/' . $server); 
$data=json_decode($playeronline,true); 

echo $data['players']['online'];