質問

I'm trying to turn a JSON file of Xbox Live data into variables that I can use in a PHP generated image. My JSON file is here: http://www.xboxgamercard.org/gamercard/test3/xbox.php

I have tried this:

$request_url = 'xbox.php';
$json = file_get_contents($request_url);
$decode = json_decode($json, true);
var_dump($decode['gamertag'][0]);

but it just returns NULL.

I would like to use the JSON as shown here:

$gamertag = $data['Gamertag'];
echo $gamertag;
役に立ちましたか?

解決

You need to add the full url eg:

<?php
$request_url = 'http://www.xboxgamercard.org/gamercard/test3/xbox.php';

$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
?> 
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top