我想知道如何从这个json中获取一个值。
我必须接受价值" FIFA 15" (该字段是"名称")。
json(http://xboxapi.com/v2/superdeder/xboxonegames)的内容是:
{" titles":[ { " lastUnlock":" 2014-10-11T12:30:30.4788799Z", " titleId":122001257, " serviceConfigId":" 64c10100-3d40-49d5-8f1c-c99807459769", " titleType":" LiveApp", "平台":" Durango", "姓名":" YouTube", " wonAchievements":3, " currentGamerscore":0, " maxGamerscore":0 }, { " lastUnlock":" 2014-10-28T21:55:44.6766285Z", " titleId":1689264723, " serviceConfigId":" 0b430100-23ff-43cd-a287-894f64b02253", " titleType":" DGame", "平台":" Durango", " name":" FIFA 15", " wonAchievements":11, " currentGamerscore":350, " maxGamerscore":1000 }]," pagingInfo":{ " continuationToken":null, " totalRecords":2}}
使用正常的json我成功获取值但是我认为需要进行身份验证。
这是文档:https://xboxapi.com/documentation。
我在altervista中使用php。
谢谢!
答案 0 :(得分:1)
您首先需要使用xbox gametag在xboxapi.com上登录,或者您可以专门为此网站创建新的游戏标签。完成此操作后,您将看到自己的XboxAPI API密钥'在该网站的个人资料页面上,这是您的身份验证密钥。
现在,您可以使用Curl来检索所需的信息。
$url = 'https://xboxapi.com/v2/superdeder/xboxonegames';
$headers = array('X-AUTH: ***Your API key here***');
$session = curl_init($url);
curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
curl_setopt($session, CURLOPT_HTTPHEADER, $headers);
$response = curl_exec($session);
curl_close($session);
$myArray = json_decode($response, true);
// You now have the JSON as an array file called $myArray,
// you can see what's inside the array with:
echo '<pre>';
var_dump($myArray);
echo '</pre>';
//The game FIFA15 is 3rd in your games list, so to retrieve the name you would use:
echo $myArray["titles"][2]["name"];