2017-10-11 76 views

回答

0

的API響應包含一個數組( ),因此你必須選擇哪個(遊戲?)來從中解放出來。 (?遊戲),如果你只是想使用第一個下面的代碼應該滿足您的需求:

$url = "http://api.suredbits.com/nfl/v0/stats/brown/zach"; 
$json = file_get_contents($url); 
$json_data = json_decode($json, true); 
echo $json_data[0]["defense"]["tackle"]; 
0

值滑車是另一個對象的防守中,所以你應該儘量

echo $json_data[0]["defence"]["tackle"]; 
+0

現在它說,防守是不確定的 – Err404r

+0

解決它。 echo $ json_data [0] [「defense」] [「tackle」]; – Err404r

+0

ohh沒有注意到整個json是一個數組 –

1
$url = "http://api.suredbits.com/nfl/v0/stats/brown/zach"; 
$json = file_get_contents($url); 
$json_data = json_decode($json, true); 
foreach($json_data as $item) 
{ 
    echo $item["defence"]["tackle"]; 
}