我只是想顯示爲一個數組的API響應,但什麼是錯的,我並不覺得:如何將JSON API顯示爲數組?
API的答案:
{"status":"OK","minecrafts":[{"id":411,"ip":"2452453","name":"EdenCraft","port":23,"ram":512,"leaf_id":1522,"ftp_password":"1231235312","subscription_end":"2014-02-06T19:56:29.000Z"}]}
我的PHP代碼:
<?php
$url = "http://api.edenservers.fr/minecraft?user_id=id&api_key=key";
$data = file_get_contents($url); // Opening the Query URL
$data = json_decode($data, true); // Decoding the obtained JSON data
if(count($data) > 0) {
foreach($data as $rank => $donnees) {
echo "<u>" . $rank ."</u> : ". $rank;
echo "<br />";
}
}
else {
echo "Rien n'a été troué.";
}
?>
這是何等的顯示在我的儀表盤:
status : status
minecrafts : minecrafts
謝謝你的幫助 !
它的工作原理!謝謝 ! –