我想從 API 打印結果......但它不工作......我不知道有什么問題我試圖這樣做但得到了這個并且它不工作:<?php$api = 'https://api.battlemetrics.com/servers/'; // the main API for servers.$server = '5090469'; // the number of the server you will get the info from most of thime something like 5484856.$api_full = $api . $server; // bringing them together.$json = file_get_contents("$api_full"); // Putting the content of the file in a variable.$response = json_decode($json, true); // decode the JSON feedif ($response['data']['status'] == "online") { echo "ONLINE"; } else { echo "OFFLINE"; };?>如果您想查看 json 響應,請附加以下鏈接:https ://api.battlemetrics.com/servers/5090469提前感謝您的提示和幫助。
1 回答

慕村9548890
TA貢獻1884條經驗 獲得超4個贊
看起來您只是在 if 語句中缺少一個鍵。
它應該是: if($response['data']['attributes']['status'] == "online")
- 1 回答
- 0 關注
- 102 瀏覽
添加回答
舉報
0/150
提交
取消