0

i have the url and need to get the value of 'tackle' from this json file. http://api.suredbits.com/nfl/v0/stats/brown/zach

I tried this but its throwing errors -> undefined index

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

3 Answers 3

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"];
}
Sign up to request clarification or add additional context in comments.

Comments

0

The API response contains an array (of games?), therefore you must select which (game?) to pull the tackle from. If you would just like to use the first (game?) the following code should suit your needs:

$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"];

Comments

0

The value tackle is within another object defence so you should try

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

2 Comments

solved it. echo $json_data[0]["defense"]["tackle"];
ohh didn't notice the whole json was an array

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.