2017-10-11 136 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"]; 
}