CSharp · Console
using System;
using System.Collections.Generic;
using System.IO;
using System.Net;
using System.Linq;
using Newtonsoft.Json;
public class Program
{
public static void Main()
{
Game game = GetGameData(570);
// Note: some null checks are omitted here for brevity.
if (game.success)
{
Data data = game.data;
Console.WriteLine("Name: " + data.name);
Console.WriteLine("Type: " + data.type);
Console.WriteLine("Description: " + data.short_description);
Console.WriteLine("Free: " + (data.is_free ? "Yes": "No"));
Console.WriteLine("Genres: " + string.Join(", ", data.genres.Select(g => g.description)));
if (data.categories != null)
Console.WriteLine("Categories: " + string.Join(", ", data.categories.Select(g => g.description)));
Console.WriteLine("Web site: " + data.website);
Console.WriteLine("Release date: " + data.release_date.date);
Console.WriteLine("Developers: " + string.Join(", ", data.developers));
Console.WriteLine("Platforms: " + GetPlatformString(data.platforms));
}
else
{
Console.WriteLine("Unsuccessful");
}
}
private static string GetPlatformString(Platforms platforms)
{
List<string> list = new List<string>();
if (platforms.windows) list.Add("windows");
if (platforms.mac) list.Add("mac");
if (platforms.linux) list.Add("linux");
return string.Join(", ", list);
}
public static Game GetGameData(int GameId)
{
var url = "https://store.steampowered.com/api/appdetails/?appids=" + GameId.ToString();
//Game GameData = _download_serialized_json_data<Game>(url);
HttpWebRequest WebReq = (HttpWebRequest)WebRequest.Create(string.Format(url));
WebReq.Method = "GET";
HttpWebResponse WebResp = (HttpWebResponse)WebReq.GetResponse();
Console.WriteLine(WebResp.StatusCode);
Console.WriteLine(WebResp.Server);
string jsonString;
using (Stream stream = WebResp.GetResponseStream())
{
StreamReader reader = new StreamReader(stream, System.Text.Encoding.UTF8);
jsonString = reader.ReadToEnd();
}
var dict = JsonConvert.DeserializeObject<Dictionary<string, Game>>(jsonString);
Game gameData = dict[GameId.ToString()];
return gameData;
}
}
public class Game
{
public bool success { get; set; }
public Data data { get; set; }
}
public class Data
{
public string type { get; set; }
public string name { get; set; }
public int steam_appid { get; set; }
public int required_age { get; set; }
public bool is_free { get; set; }
public List<int> dlc { get; set; }
public string detailed_description { get; set; }
public string about_the_game { get; set; }
public string short_description { get; set; }
public string supported_languages { get; set; }
public string reviews { get; set; }
public string header_image { get; set; }
public string website { get; set; }
//public PcRequirements pc_requirements { get; set; }
//public MacRequirements mac_requirements { get; set; }
//public LinuxRequirements linux_requirements { get; set; }
public List<string> developers { get; set; }
public List<string> publishers { get; set; }
public List<int> packages { get; set; }
public List<PackageGroup> package_groups { get; set; }
public Platforms platforms { get; set; }
public Metacritic metacritic { get; set; }
public List<Category> categories { get; set; }
public List<Genre> genres { get; set; }
public List<Screenshot> screenshots { get; set; }
public List<Movie> movies { get; set; }
public Recommendations recommendations { get; set; }
public ReleaseDate release_date { get; set; }
public SupportInfo support_info { get; set; }
public string background { get; set; }
}
public class PcRequirements
{
public string minimum { get; set; }
}
public class MacRequirements
{
public string minimum { get; set; }
}
public class LinuxRequirements
{
public string minimum { get; set; }
}
public class PackageGroup
{
public string name { get; set; }
public string title { get; set; }
public string description { get; set; }
public string selection_text { get; set; }
public string save_text { get; set; }
public int display_type { get; set; }
public string is_recurring_subscription { get; set; }
public List<Sub> subs { get; set; }
}
public class Sub
{
public int packageid { get; set; }
public string percent_savings_text { get; set; }
public int percent_savings { get; set; }
public string option_text { get; set; }
public string option_description { get; set; }
public string can_get_free_license { get; set; }
public bool is_free_license { get; set; }
public int price_in_cents_with_discount { get; set; }
}
public class Platforms
{
public bool windows { get; set; }
public bool mac { get; set; }
public bool linux { get; set; }
}
public class Metacritic
{
public int score { get; set; }
public string url { get; set; }
}
public class Category
{
public int id { get; set; }
public string description { get; set; }
}
public class Genre
{
public string id { get; set; }
public string description { get; set; }
}
public class Screenshot
{
public int id { get; set; }
public string path_thumbnail { get; set; }
public string path_full { get; set; }
}
public class Movie
{
public int id { get; set; }
public string name { get; set; }
public string thumbnail { get; set; }
public Webm webm { get; set; }
public bool highlight { get; set; }
}
public class Webm
{
[JsonProperty("480")]
public string _480 { get; set; }
public string max { get; set; }
}
public class Recommendations
{
public int total { get; set; }
}
public class ReleaseDate
{
public bool coming_soon { get; set; }
public string date { get; set; }
}
public class SupportInfo
{
public string url { get; set; }
public string email { get; set; }
}