简体   繁体   中英

Load steam applist as JSON file

I've been trying to load the Steam app list from this url " https://api.steampowered.com/ISteamApps/GetAppList/v2/?key=XXXXXXXXXetc ." and I've tried all combinations I think, with AJAX, downloading it using PHP, but I haven't been able to find a way that works, hope you can help!

Thanks in advance, Magn0053

Try this:

<?php

$jsonString = file_get_content("https://api.steampowered.com/ISteamApps/GetAppList/v2/?key=XXXXXXXXXetc");

$listArray = json_decode($jsonString, true);
echo "<ul id="listResults">\r\n";
foreach($listArray as $k => $v){
    echo "<li><label>$k</label>: $v</li>\r\n";
}
echo "</ul>\r\n";
?>

This can be done in JQuery too (Example: http://jsfiddle.net/Twisty/be5h65L3/ ):

$(function(){
    $("#getListBtn").click(function(){
        var url = 'https://api.steampowered.com/ISteamApps/GetAppList/v2/?key=XXXXXXXXXetc&callback=?';

        $.ajax({
            type: 'GET',
            url: url,
            async: false,
            jsonpCallback: 'jsonCallback',
            contentType: "application/json",
            dataType: 'jsonp',
            success: function(data) {
               $.each(data, function(k, v){
                   $("#listResults").append("<li><label>" + k + "<label>: " + v + "</li>");
               });
            },
            error: function(e) {
               console.log(e.message);
            }
        });
    });
});

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