2014-10-31 43 views
0

我想知道如何從這個json中獲取一個值。如何獲取這個json的值?

我必須把值「國際足聯15」(該字段是「名稱」)。

的JSON(http://xboxapi.com/v2/superdeder/xboxonegames)的含量是這樣的:

{ 「標題」:[{ 「lastUnlock」: 「2014-10-11T12:30:30.4788799Z」, 「titleId 「:122001257, 」serviceConfigId「: 」64c10100-3d40-49d5-8f1c-c99807459769「, 」titleType「: 」LiveApp「, 」平臺「: 」杜蘭戈「, 」名「: 」YouTube「 的視頻, 」賺取成就「:3, 」currentGamerscore「:0, 」maxGamerscore「:0 },{ 「lastUnlock」: 「2014-10-28T21:55:44.6766285Z」, 「titleId」:1689264723, 「serviceConfigId」: 「0b430100-23ff-43cd-a287-894f64b02253」, 「titleType 「: 」DGame「, 」平臺「: 」杜蘭戈「, 」名稱「: 」FIFA 15「, 」earnedAchievements「:11, 」currentGamerscore「:350, 」maxGamerscore「:1000 }],」 pagingInfo「:{ 」continuationToken「:空, 」總記錄「:2}}

與正常的JSON我succee d a採取的價值,但與此我相信有一個身份驗證的需要。

這是文檔:https://xboxapi.com/documentation

我在altervista中使用php。

謝謝!

+0

爲什麼你認爲你需要身份驗證時,值是在JSON? – Sasa 2014-10-31 10:56:22

+0

因爲這裏https://xboxapi.com/documentation, 有命令X-AUTH和哪裏是短語 「YOUR_AUTH_KEY_HERE」, 如果我日誌中會出現一個API密鑰,並在其他地方... 這是另一個問題,但與此我沒有問題.. [鏈接](http://stackoverflow.com/questions/26606514/how-can-i-extract-the-value-of-this-json-in -php)[鏈接]。 – 2014-10-31 11:10:32

+0

然後把你的API密鑰放在那裏。我不明白你的問題... – Sasa 2014-10-31 11:13:31

回答

1

您首先需要使用xbox遊戲標籤登錄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"]; 
+0

嘿斯洛瑟,謝謝你的回覆。 但返回值爲「null」。 可能的解決方案? 謝謝! – 2014-11-10 13:49:11

+0

我有解決方案! 在「URL」變量中有「HTTP」,但正確的格式是「HTTPS」! 真的謝謝! – 2014-11-10 13:56:47

+0

我已經編輯了我對https的回答,如果這回答了你的問題,你能設置你的問題來回答嗎? :) – Sloeser 2014-11-11 01:39:41