[英]can't get right api result from json (using json_decode)
我想從 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 feed
if ($response['data']['status'] == "online") {
echo "ONLINE";
} else {
echo "OFFLINE";
};
?>
如果您想查看 json 響應,請附加以下鏈接: https : //api.battlemetrics.com/servers/5090469
在此先感謝您的提示和幫助。
看起來您只是在 if 語句中缺少一個鍵。
應該是: if($response['data']['attributes']['status'] == "online")
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.