2

I wanna make app where i have list with my games on steam. I get Steam API Key and i get JSON with my games data but i don't know how i can get this to my ListView or something like this.

Im trying to find some tutorials and i find with Newtonsoft.JSON but i still get errors.

How JSON Looks:

{
   "response":{
      "game_count":27,
      "games":[
         {
            "appid":730,
            "name":"Counter-Strike: Global Offensive",
            "playtime_2weeks":986,
            "playtime_forever":30571,
            "img_icon_url":"69f7ebe2735c366c65c0b33dae00e12dc40edbe4",
            "img_logo_url":"d0595ff02f5c79fd19b06f4d6165c3fda2372820",
            "has_community_visible_stats":true,
            "playtime_windows_forever":1600,
            "playtime_mac_forever":0,
            "playtime_linux_forever":0
         },
         {
            "appid":224260,
            "name":"No More Room in Hell",
            "playtime_forever":0,
            "img_icon_url":"684de0d9c5749b5ddd52f120894fd97efd620b1d",
            "img_logo_url":"670e9aba35dc53a6eb2bc686d302d357a4939489",
            "has_community_visible_stats":true,
            "playtime_windows_forever":0,
            "playtime_mac_forever":0,
            "playtime_linux_forever":0
         },
         {
            "appid":232010,
            "name":"Euro Truck Simulator",
            "playtime_forever":11,
            "img_icon_url":"6b1bb4a4e2b1e0d85ad0b3e2d6d15a0258aa43a0",
            "img_logo_url":"fa3886315d9586671506c7149c1e4ecae653ce13",
            "has_community_visible_stats":true,
            "playtime_windows_forever":0,
            "playtime_mac_forever":0,
            "playtime_linux_forever":0
         }
      ]
   }
}

I trying this but it's doesn't works.

json = wc.DownloadString("http://api.steampowered.com/IPlayerService/GetOwnedGames/v0001/?key=D4718FA8ED43C531523CF79310BE52FE&steamid=76561198440001695&include_appinfo=1");
dynamic results = JsonConvert.DeserializeObject(json);
var appid = results.appid();

i get error:

  • $exception {"Component „Newtonsoft.Json.Linq.JObject” doesn't contain a definition „appid”."} Microsoft.CSharp.RuntimeBinder.RuntimeBinderException
1

1 Answer 1

3

You should deserialize this string with the generic deserializer method of Newtonsoft.

try making a new class:

 public partial class GameResponse
{
    [JsonProperty("response")]
    public Response Response { get; set; }
}

public partial class Response
{
    [JsonProperty("game_count")]
    public long GameCount { get; set; }

    [JsonProperty("games")]
    public Game[] Games { get; set; }
}

public partial class Game
{
    [JsonProperty("appid")]
    public long Appid { get; set; }

    [JsonProperty("name")]
    public string Name { get; set; }

    [JsonProperty("playtime_2weeks", NullValueHandling = NullValueHandling.Ignore)]
    public long? Playtime2Weeks { get; set; }

    [JsonProperty("playtime_forever")]
    public long PlaytimeForever { get; set; }

    [JsonProperty("img_icon_url")]
    public string ImgIconUrl { get; set; }

    [JsonProperty("img_logo_url")]
    public string ImgLogoUrl { get; set; }

    [JsonProperty("has_community_visible_stats")]
    public bool HasCommunityVisibleStats { get; set; }

    [JsonProperty("playtime_windows_forever")]
    public long PlaytimeWindowsForever { get; set; }

    [JsonProperty("playtime_mac_forever")]
    public long PlaytimeMacForever { get; set; }

    [JsonProperty("playtime_linux_forever")]
    public long PlaytimeLinuxForever { get; set; }
}

then use:

var json = wc.DownloadString("http://api.steampowered.com/IPlayerService/GetOwnedGames/v0001/?key=D4718FA8ED43C531523CF79310BE52FE&steamid=76561198440001695&include_appinfo=1");
var results = JsonConvert.DeserializeObject<GameResponse>(json);

Fiddle: https://dotnetfiddle.net/Nf2LdB

Sign up to request clarification or add additional context in comments.

2 Comments

that's works but how i can add this data to ex. ListView?
ListView in winforms ? maybe this could help:stackoverflow.com/questions/43841962/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.