如何搜索Steam游戏API的JSON输出?

问题描述 投票:0回答:1

我正在使用以下API:

http://api.steampowered.com/ISteamApps/GetAppList/v0002/?format=json

https://store.steampowered.com/api/appdetails?appids=GAMEID(配子范例:“ 730”-反击)

我两者的目标都是在它们中搜索数据。例如,我希望第一个API根据游戏的ID给我一个游戏的名称,第二个API给我一个有关游戏的特定信息,例如,如果它有交易卡(API中的ID:29)。

我尝试了几件事,但是由于我不太了解JSON,所以我有点迷失了,因此我非常感谢您的帮助。我对PHP和JS解决方案都持开放态度。

javascript php steam steam-web-api
1个回答
0
投票

在PHP中,您可以使用json_decode()函数将JSON数据转换为数组。您可以像访问经典数组一样访问它们的值:

$appID = 730 ;
$url = 'https://store.steampowered.com/api/appdetails?appids=' . $appID ;

$content = file_get_contents($url) ; // retrieve the JSON data string from the website
$data = json_decode($content, true); // convert the JSON string into PHP array 

echo $data[$appID]['data']['name'] ; // Counter-Strike: Global Offensive
var_dump($data[$appID]['data']['is_free']); // bool(true)
© www.soinside.com 2019 - 2024. All rights reserved.