0

我正在尝试将Xbox Live 数据文件转换为可在生成的图像JSON中使用的变量。PHP我的 JSON 文件在这里: http: //www.xboxgamercard.org/gamercard/test3/xbox.php

我试过这个:

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

但它只是返回NULL

我想使用如下所示的 JSON:

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

1 回答 1

0

您需要添加完整的网址,例如:

<?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
?> 
于 2012-01-28T23:08:18.320 回答