user1175820 user1175820 - 1 year ago 80
PHP Question

Decoding JSON into an array for a xbox live image script?

I'm trying to turn a

file of Xbox Live data into variables that I can use in a
generated image. My JSON file is here:

I have tried this:

$request_url = 'xbox.php';
$json = file_get_contents($request_url);
$decode = json_decode($json, true);

but it just returns

I would like to use the JSON as shown here:

$gamertag = $data['Gamertag'];
echo $gamertag;

Answer Source

You need to add the full url eg:

$request_url = '';

$json = file_get_contents($request_url);
$data = json_decode($json, true);

//Example output
echo $data['gamertag']; //Crylics
echo $data['gamerscore']; //7492

/* Too access the recent_games key you will need
   to loop through it or access it like
echo $data['recent_games'][1]['title']; //Call of Duty: WaW
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download