0

I've managed to get the data back through ajax, then I parse it, but I don't understand how to get the items.

API Link:

http://api.steampowered.com/IPlayerService/GetRecentlyPlayedGames/v0001/?key=mytid&steamid=76561198033943113&format=json

JSON Response

{
  "response": {
    "total_count": 1,
    "games": [{
      "appid": 252950,
      "name": "Rocket League",
      "playtime_2weeks": 1631,
      "playtime_forever": 28185,
      "img_icon_url": "217214f6bd922a8da8bdd684aa94b1ef8e7724d1",
      "img_logo_url": "58d7334290672887fdd47e25251f291b812c895e"
    }]

  }
}

I'm showing you the link so you can understand the hierarchy.

So yea I get the data back into the success and parse it:

JSON.parse(result);

Then I do:

alert(result); //- works and shows me the data.
alert(result.response.total_count); // - doesn't work.   

I don't understand how to get the items out.

Thanks!

Brad Larson
  • 170,088
  • 45
  • 397
  • 571
hashtagbad
  • 97
  • 11

1 Answers1

1

You think that alert(result); is working because you see the data, but infact it is not working correctly, as you shouldn't see the array data by alert-ing the object. JSON.parse() will return the object containing your json array, so you need to assign it to variable, since it is not overwriting your result variable...

Try:

var res = JSON.parse(result);
alert(res.response.total_count);
Yuri
  • 3,082
  • 3
  • 28
  • 47