亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

無法從 json 獲得正確的 api 結果(使用 json_decode)

無法從 json 獲得正確的 api 結果(使用 json_decode)

PHP
肥皂起泡泡 2022-07-22 16:07:58
我想從 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")


查看完整回答
反對 回復 2022-07-22
  • 1 回答
  • 0 關注
  • 102 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號