Get Steam game information

I have been away from the coding scene for a bit and trying to get my head back into the game. Here I am going to show an example. Let’s say I have this piece of text that is returned to me when I enter a certain url (Example: http://api.steampowered.com/ISteamUserStats/GetUserStatsForGame/v0002/?appid=730&key=KEY&steamid=STEAMID":

{
    "playerstats": {
        "steamID": "7656-EDITED-OUT",
        "gameName": "ValveTestApp260",
        "stats": [
            {
                "name": "total_kills",
                "value": 110527
            },
            {
                "name": "total_deaths",
                "value": 95930
            },
            {
                "name": "total_time_played",
                "value": 5784386
            },
            {
                "name": "total_planted_bombs",
                "value": 2726
            },
            {
                "name": "total_defused_bombs",
                "value": 594
            },
            {
                "name": "total_wins",
                "value": 26937
            },
            ...
        ]
    }
}

How would I take this information from the website and set it as a variable so I can put it in my website?

Thanks!

This is JSON. In JavaScript:


var text = '{ "employees" : [' +
'{ "firstName":"John" , "lastName":"Doe" },' +
'{ "firstName":"Anna" , "lastName":"Smith" },' +
'{ "firstName":"Peter" , "lastName":"Jones" } ]}';

var obj = JSON.parse(text);


 <p id="demo"></p>

<script>
document.getElementById("demo").innerHTML =
obj.employees[1].firstName + " " + obj.employees[1].lastName;
</script> 

See: http://www.w3schools.com/js/js_json.asp (Converting a JSON Text to a JavaScript Object)

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.