Hallo, ich versuche mit Hilfe von json.net den Array der Steam Store API auszulesen.
store.steampowered.com/api/appdetails?appids=730
Allerdings bekomme ich immer folgende Fehlermeldung:
Meine Klassen:
Spoiler anzeigen
Der Main Teil:
store.steampowered.com/api/appdetails?appids=730
Allerdings bekomme ich immer folgende Fehlermeldung:
Quellcode
- Cannot deserialize the current JSON object (e.g. {"name":"value"}) into type 'System.Collections.Generic.List`1[ShopReader.Program+RootObject]' because the type requires a JSON array (e.g. [1,2,3]) to deserialize correctly. To fix this error either change the JSON to a JSON array (e.g. [1,2,3]) or change the deserialized type so that it is a normal .NET type (e.g. not a primitive type like integer, not a collection type like an array or List) that can be deserialized from a JSON object. JsonObjectAttribute can also be added to the type to force it to deserialize from a JSON object.
Meine Klassen:
C#-Quellcode
- 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 PriceOverview
- {
- public string currency { get; set; }
- public int initial { get; set; }
- public int final { get; set; }
- public int discount_percent { 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 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 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 Webm
- {
- public string __invalid_name__480 { get; set; }
- public string max { 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 Recommendations
- {
- public int total { get; set; }
- }
- public class Highlighted
- {
- public string name { get; set; }
- public string path { get; set; }
- }
- public class Achievements
- {
- public int total { get; set; }
- public List<Highlighted> highlighted { 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; }
- }
- 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 string controller_support { get; set; }
- public string detailed_description { get; set; }
- public string about_the_game { get; set; }
- public string supported_languages { 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 PriceOverview price_overview { 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 Achievements achievements { get; set; }
- public ReleaseDate release_date { get; set; }
- public SupportInfo support_info { get; set; }
- public string background { get; set; }
- }
- public class steam
- {
- public bool success { get; set; }
- public Data data { get; set; }
- }
- public class RootObject
- {
- public steam steam { get; set; }
- }
Der Main Teil:
C#-Quellcode
- static void Main(string[] args)
- {
- string json = new WebClient().DownloadString("http://store.steampowered.com/api/appdetails?appids=730");
- var jobject = JsonConvert.DeserializeObject<List<RootObject>>(json);
- foreach(var datas in jobject)
- {
- Console.WriteLine(datas.steam.data.name);
- }
- Console.ReadKey();
- }