简体   繁体   中英

How to search Steam game API JSON output?

I am working with following APIs:

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

https://store.steampowered.com/api/appdetails?appids=GAMEID (gameid example: "730" - counter strike)

My goal with both of these is to search them for data. For example I want the first API to give me a name of a game based on it's ID and the second one to give me specific information about a game for example if it has trading cards (id:29 in the API).

I tried a few things but I am kinda lost on this beacuse I don't really understand JSON so I would really appreciate some help.
I am open to both PHP and JS solutions.

IN PHP, you can use the json_decode() function to convert JSON data into an array. You can them access the values as you do for a classic array:

$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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM