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

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

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

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

PHP
忽然笑 2022-08-05 10:22:24
我想打印來自 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 回答

?
慕慕森

TA貢獻1856條經驗 獲得超17個贊

看起來您只是在 if 語句中缺少一個鍵。

它應該是:if($response['data']['attributes']['status'] == "online")


查看完整回答
反對 回復 2022-08-05
  • 1 回答
  • 0 關注
  • 111 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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