Home > Software engineering >  How do I successfully bind my HttpClient's JSON response content to a Model and return that Mod
How do I successfully bind my HttpClient's JSON response content to a Model and return that Mod

Time:10-23

Summary of the issue

I am trying to get the response content gathered from gameData to be bound into my model class, and finally to return that bound class as JSON for my frontend to receive it. Currently, I do not receive an error, but I do receive a completely null result when I try to process gameData any further than it has been currently. As it stands, gameData contains all of the JSON I am looking for, but that JSON has escape characters, or backslashes (\), inside it. I am calling Steam's API to retrieve the content stored in gameData.

What I've tried

  • Deserializing the JSON into my model class by using JsonSerializer.Deserialize<>() from System.Text.Json
  • Getting rid of the backslashes with JToken.Parse(str).ToString(), which was an answer on a different post and then trying to bind the model (which ultimately made no sense)
  • Copying the expected JSON and automatically generating my model class, whereafter I try to deserialize the content using their example statement, but still to no avail (https://json2csharp.com/)
  • Changing the ActionResult<> Type
  • Passing the gameData response content directly without model-binding to my frontend, which causes even more issues

And more...

This is my backend endpoint (running on localhost)

[HttpGet("steamapi/{SteamGameId}")]
    public async Task<ActionResult<Root>> GetSteamApiGameById(int SteamGameId)
    {
        using (var httpClient = _httpClientFactory.CreateClient())
        {
            using HttpResponseMessage? response = await httpClient.GetAsync($"https://store.steampowered.com/api/appdetails?appids={SteamGameId}");

            string? gameData;
            Root? formattedGameData;
            if (response.IsSuccessStatusCode)
            {
                gameData = await response.Content.ReadAsStringAsync();
                formattedGameData = JsonSerializer.Deserialize<Root>(gameData);
            }
            else
            {
                formattedGameData = null!;
            }

            if (formattedGameData != null)
                return Ok(formattedGameData);
            return NotFound();
        }
    }

This is the expected JSON

{
"249130": {
    "success": true,
    "data": {
        "type": "game",
        "name": "LEGO® Marvel™ Super Heroes",
        "steam_appid": 249130,
        "required_age": 0,
        "is_free": false,
        "controller_support": "full",
        "dlc": [
            256320,
            256321
        ],
        "detailed_description": "<strong>LEGO® Marvel™ Super Heroes</strong> features an original story crossing the entire Marvel Universe. Players take control of Iron Man, Spider-Man, the Hulk, Captain America, Wolverine and many more Marvel characters as they unite to stop Loki and a host of other Marvel villains from assembling a super-weapon capable of destroying the world. Players will chase down Cosmic Bricks as they travel across LEGO Manhattan and visit key locations from the Marvel Universe, such as Stark Tower, Asteroid M, a Hydra base and the X-Mansion.<br><br><ul class=\"bb_ul\"><li>Smash, swing  and fly in the first LEGO videogame featuring more than 100 of your favorite Super Heroes and Super Villains from the Marvel Universe, including  Iron Man, Wolverine, the Hulk, Spider-Man, Captain America, Black Widow, Loki and Deadpool.<br></li><li>Help save Earth as your favorite Marvel character with your super-cool strengths and abilities:  <br><ul class=\"bb_ul\"><li>Iron Man flies, hovers, shoots missiles and unleashes a powerful unibeam directly from his chest.<br></li><li>Spider-Man shoots webs, uses his spider-senses to spot objects invisible to others, crawls up walls and, of course, web-slings. <br></li><li>Captain America throws his mighty shield at objects and enemies, embeds it into a wall to create a platform, and protects himself from damage. <br></li><li>Hulk smashes!</li></ul></li><li>Perform new and powerful moves as “BIG-fig” characters like Hulk and Abomination.  Leave a path of destruction as you smash through LEGO walls and throw cars using hyper strength.<br></li><li>Discover LEGO Manhattan like never before, and travel to iconic locations from the Marvel Universe, such as the X-Mansion, Asteroid M and Asgard.<br></li><li>Create unique Super Heroes with customizable characters.<br></li><li>Enjoy an exciting original story, filled with classic LEGO videogame adventure and humor.</li></ul>",
        "about_the_game": "<strong>LEGO® Marvel™ Super Heroes</strong> features an original story crossing the entire Marvel Universe. Players take control of Iron Man, Spider-Man, the Hulk, Captain America, Wolverine and many more Marvel characters as they unite to stop Loki and a host of other Marvel villains from assembling a super-weapon capable of destroying the world. Players will chase down Cosmic Bricks as they travel across LEGO Manhattan and visit key locations from the Marvel Universe, such as Stark Tower, Asteroid M, a Hydra base and the X-Mansion.<br><br><ul class=\"bb_ul\"><li>Smash, swing  and fly in the first LEGO videogame featuring more than 100 of your favorite Super Heroes and Super Villains from the Marvel Universe, including  Iron Man, Wolverine, the Hulk, Spider-Man, Captain America, Black Widow, Loki and Deadpool.<br></li><li>Help save Earth as your favorite Marvel character with your super-cool strengths and abilities:  <br><ul class=\"bb_ul\"><li>Iron Man flies, hovers, shoots missiles and unleashes a powerful unibeam directly from his chest.<br></li><li>Spider-Man shoots webs, uses his spider-senses to spot objects invisible to others, crawls up walls and, of course, web-slings. <br></li><li>Captain America throws his mighty shield at objects and enemies, embeds it into a wall to create a platform, and protects himself from damage. <br></li><li>Hulk smashes!</li></ul></li><li>Perform new and powerful moves as “BIG-fig” characters like Hulk and Abomination.  Leave a path of destruction as you smash through LEGO walls and throw cars using hyper strength.<br></li><li>Discover LEGO Manhattan like never before, and travel to iconic locations from the Marvel Universe, such as the X-Mansion, Asteroid M and Asgard.<br></li><li>Create unique Super Heroes with customizable characters.<br></li><li>Enjoy an exciting original story, filled with classic LEGO videogame adventure and humor.</li></ul>",
        "short_description": "LEGO® Marvel™ Super Heroes features an original story crossing the entire Marvel Universe. Players take control of Iron Man, Spider-Man, the Hulk, Captain America, Wolverine and many more Marvel characters as they unite to stop Loki and a host of other Marvel villains from assembling a super-weapon capable of destroying the world.",
        "supported_languages": "English<strong>*</strong>, French<strong>*</strong>, Italian, German<strong>*</strong>, Spanish - Spain<strong>*</strong>, Dutch, Portuguese - Brazil, Danish, Polish, Russian<br><strong>*</strong>languages with full audio support",
        "header_image": "https://cdn.akamai.steamstatic.com/steam/apps/249130/header.jpg?t=1573497453",
        "website": "http://www.lego.com/marvelsuperheroes",
        "pc_requirements": {
            "minimum": "<strong>Minimum:</strong><br><ul class=\"bb_ul\"><li><strong>OS:</strong> Windows®XP SP3, Windows Vista/7/8 with latest service packs and updates installed<br></li><li><strong>Processor:</strong> AMD Athlon 64 X2 EE 3800  (2*2000 Mhz) or similar Intel CPU, such as Intel Pentium Dual Core E2180 (2*2000 Mhz)<br></li><li><strong>Memory:</strong> 2 GB RAM<br></li><li><strong>Graphics:</strong> NVIDIA GeForce 7600 GS or ATI Radeon X1950 Pro or better<br></li><li><strong>DirectX:</strong> Version 10<br></li><li><strong>Network:</strong> Broadband Internet connection<br></li><li><strong>Storage:</strong> 7 GB available space</li></ul>",
            "recommended": "<strong>Recommended:</strong><br><ul class=\"bb_ul\"><li><strong>OS:</strong> Windows XP/Vista/7/8<br></li><li><strong>Processor:</strong> AMD or Intel Quad Core running at 4*2600 Mhz<br></li><li><strong>Memory:</strong> 4 GB RAM<br></li><li><strong>Graphics:</strong> NVIDIA GeForce GTX 480 or ATI Radeon HD 5850 or better<br></li><li><strong>DirectX:</strong> Version 11<br></li><li><strong>Network:</strong> Broadband Internet connection<br></li><li><strong>Storage:</strong> 8 GB available space</li></ul>"
        },
        "mac_requirements": {
            "minimum": "<strong>Minimum:</strong><br><ul class=\"bb_ul\"><li><strong>OS:</strong> 10.8.5<br></li><li><strong>Processor:</strong> 1.8 GHz Intel Core 2 Duo (Dual-Core)<br></li><li><strong>Memory:</strong> 4 GB RAM<br></li><li><strong>Graphics:</strong> 256MB VRAM<br></li><li><strong>Storage:</strong> 7 GB available space<br></li><li><strong>Additional Notes:</strong> The following graphics cards are not supported: ATI X1xxx series, ATI HD2xxx series, Intel GMA series, Intel HD3000, NVIDIA 7xxx series, NVIDIA 8xxx series, NVIDIA 9400 and NVIDIA 320M.</li></ul>",
            "recommended": "<strong>Recommended:</strong><br><ul class=\"bb_ul\"><li><strong>OS:</strong> 10.9.3<br></li><li><strong>Processor:</strong> 2.4 GHz<br></li><li><strong>Memory:</strong> 8 GB RAM<br></li><li><strong>Graphics:</strong> 1GB VRAM<br></li><li><strong>Storage:</strong> 7 GB available space<br></li><li><strong>Additional Notes:</strong> The following graphics cards are not supported: ATI X1xxx series, ATI HD2xxx series, Intel GMA series, Intel HD3000, NVIDIA 7xxx series, NVIDIA 8xxx series, NVIDIA 9400 and NVIDIA 320M.</li></ul>"
        },
        "linux_requirements": [],
        "legal_notice": "<strong>LEGO MARVEL SUPER HEROES</strong> software © 2013 TT Games Publishing Ltd. Produced by TT Games under license from the LEGO Group. LEGO, the LEGO logo, the Brick and the Knob configurations and the Minifigure are trademarks of the LEGO Group. © 2013 The LEGO Group. © MARVEL. All other trademarks and copyrights are the property of their respective owners.  All rights reserved.<br><br>WB GAMES LOGO, WB SHIELD: ™ & © Warner Bros. Entertainment Inc.<br>(s13)",
        "developers": [
            "Traveller's Tales"
        ],
        "publishers": [
            "Warner Bros. Interactive Entertainment"
        ],
        "price_overview": {
            "currency": "ZAR",
            "initial": 21900,
            "final": 21900,
            "discount_percent": 0,
            "initial_formatted": "",
            "final_formatted": "R 219.00"
        },
        "packages": [
            33644
        ],
        "package_groups": [
            {
                "name": "default",
                "title": "Buy LEGO® Marvel™ Super Heroes",
                "description": "",
                "selection_text": "Select a purchase option",
                "save_text": "",
                "display_type": 0,
                "is_recurring_subscription": "false",
                "subs": [
                    {
                        "packageid": 33644,
                        "percent_savings_text": " ",
                        "percent_savings": 0,
                        "option_text": "LEGO Marvel Super Heroes - R 219.00",
                        "option_description": "",
                        "can_get_free_license": "0",
                        "is_free_license": false,
                        "price_in_cents_with_discount": 21900
                    }
                ]
            }
        ],
        "platforms": {
            "windows": true,
            "mac": false,
            "linux": false
        },
        "metacritic": {
            "score": 78,
            "url": "https://www.metacritic.com/game/pc/lego-marvel-super-heroes?ftag=MCD-06-10aaa1f"
        },
        "categories": [
            {
                "id": 2,
                "description": "Single-player"
            },
            {
                "id": 1,
                "description": "Multi-player"
            },
            {
                "id": 24,
                "description": "Shared/Split Screen"
            },
            {
                "id": 22,
                "description": "Steam Achievements"
            },
            {
                "id": 28,
                "description": "Full controller support"
            },
            {
                "id": 23,
                "description": "Steam Cloud"
            },
            {
                "id": 41,
                "description": "Remote Play on Phone"
            },
            {
                "id": 42,
                "description": "Remote Play on Tablet"
            },
            {
                "id": 43,
                "description": "Remote Play on TV"
            },
            {
                "id": 44,
                "description": "Remote Play Together"
            }
        ],
        "genres": [
            {
                "id": "1",
                "description": "Action"
            },
            {
                "id": "25",
                "description": "Adventure"
            }
        ],
        "screenshots": [
            {
                "id": 0,
                "path_thumbnail": "https://cdn.akamai.steamstatic.com/steam/apps/249130/ss_ae02f99f0c999910d7615adc299ebeb311882b8e.600x338.jpg?t=1573497453",
                "path_full": "https://cdn.akamai.steamstatic.com/steam/apps/249130/ss_ae02f99f0c999910d7615adc299ebeb311882b8e.1920x1080.jpg?t=1573497453"
            },
            {
                "id": 1,
                "path_thumbnail": "https://cdn.akamai.steamstatic.com/steam/apps/249130/ss_ab3a235ddbddfd740e34271a508a6afd6ff099d2.600x338.jpg?t=1573497453",
                "path_full": "https://cdn.akamai.steamstatic.com/steam/apps/249130/ss_ab3a235ddbddfd740e34271a508a6afd6ff099d2.1920x1080.jpg?t=1573497453"
            },
            {
                "id": 2,
                "path_thumbnail": "https://cdn.akamai.steamstatic.com/steam/apps/249130/ss_1a16e90d51f02fd022b071d00b286e71234cea4f.600x338.jpg?t=1573497453",
                "path_full": "https://cdn.akamai.steamstatic.com/steam/apps/249130/ss_1a16e90d51f02fd022b071d00b286e71234cea4f.1920x1080.jpg?t=1573497453"
            },
            {
                "id": 3,
                "path_thumbnail": "https://cdn.akamai.steamstatic.com/steam/apps/249130/ss_03aa85cb0f02f9631accbd3714a02d55205eb70e.600x338.jpg?t=1573497453",
                "path_full": "https://cdn.akamai.steamstatic.com/steam/apps/249130/ss_03aa85cb0f02f9631accbd3714a02d55205eb70e.1920x1080.jpg?t=1573497453"
            },
            {
                "id": 4,
                "path_thumbnail": "https://cdn.akamai.steamstatic.com/steam/apps/249130/ss_1d081b323a47e43e801675c7c722fc2c5e492700.600x338.jpg?t=1573497453",
                "path_full": "https://cdn.akamai.steamstatic.com/steam/apps/249130/ss_1d081b323a47e43e801675c7c722fc2c5e492700.1920x1080.jpg?t=1573497453"
            }
        ],
        "movies": [
            {
                "id": 2029507,
                "name": "LEGO Marvel Super Heroes - Gamescom Trailer",
                "thumbnail": "https://cdn.akamai.steamstatic.com/steam/apps/2029507/movie.293x165.jpg?t=1447358906",
                "webm": {
                    "480": "http://cdn.akamai.steamstatic.com/steam/apps/2029507/movie480.webm?t=1447358906",
                    "max": "http://cdn.akamai.steamstatic.com/steam/apps/2029507/movie_max.webm?t=1447358906"
                },
                "mp4": {
                    "480": "http://cdn.akamai.steamstatic.com/steam/apps/2029507/movie480.mp4?t=1447358906",
                    "max": "http://cdn.akamai.steamstatic.com/steam/apps/2029507/movie_max.mp4?t=1447358906"
                },
                "highlight": true
            }
        ],
        "recommendations": {
            "total": 12966
        },
        "achievements": {
            "total": 45,
            "highlighted": [
                {
                    "name": "Sand Central Station",
                    "path": "https://cdn.akamai.steamstatic.com/steamcommunity/public/images/apps/249130/0c296dd974a746858d90ec6e57777b70083c77a8.jpg"
                },
                {
                    "name": "Times Square Off",
                    "path": "https://cdn.akamai.steamstatic.com/steamcommunity/public/images/apps/249130/e5afea011cdb333cd8e1404168b34d23c3ed68f6.jpg"
                },
                {
                    "name": "Exploratory Laboratory",
                    "path": "https://cdn.akamai.steamstatic.com/steamcommunity/public/images/apps/249130/e330372929590e65ee7f5df25273d89e8ad99a43.jpg"
                },
                {
                    "name": "Rock up at the Lock up",
                    "path": "https://cdn.akamai.steamstatic.com/steamcommunity/public/images/apps/249130/ab2ccde2cc89f9d503312dc25a054d5f66d8a9f1.jpg"
                },
                {
                    "name": "Rebooted, Resuited",
                    "path": "https://cdn.akamai.steamstatic.com/steamcommunity/public/images/apps/249130/7509bbb25061487cdfc203026e4887b88830501a.jpg"
                },
                {
                    "name": "Red Head Detention",
                    "path": "https://cdn.akamai.steamstatic.com/steamcommunity/public/images/apps/249130/e2a4f0f50bc0a0514672f1b08dc1bb572f80d448.jpg"
                },
                {
                    "name": "Bifrosty Reception",
                    "path": "https://cdn.akamai.steamstatic.com/steamcommunity/public/images/apps/249130/a5f9a21354040da96d0eaee95056a96e79610102.jpg"
                },
                {
                    "name": "Juggernauts and Crosses",
                    "path": "https://cdn.akamai.steamstatic.com/steamcommunity/public/images/apps/249130/110a7f4b9b3435773d198e269243aca87551cdac.jpg"
                },
                {
                    "name": "Doctor in the House",
                    "path": "https://cdn.akamai.steamstatic.com/steamcommunity/public/images/apps/249130/a8f78f9d61ae45908f7cf1ff333f51e6b007fbd2.jpg"
                },
                {
                    "name": "That Sinking Feeling",
                    "path": "https://cdn.akamai.steamstatic.com/steamcommunity/public/images/apps/249130/d179cb36f9f1dcb76e4296b9f77c8c336115092a.jpg"
                }
            ]
        },
        "release_date": {
            "coming_soon": false,
            "date": "15 Nov, 2013"
        },
        "support_info": {
            "url": "support.wbgames.com",
            "email": "[email protected] or [email protected]"
        },
        "background": "https://cdn.akamai.steamstatic.com/steam/apps/249130/page_bg_generated_v6b.jpg?t=1573497453",
        "background_raw": "https://cdn.akamai.steamstatic.com/steam/apps/249130/page.bg.jpg?t=1573497453",
        "content_descriptors": {
            "ids": [],
            "notes": null
        }
    }
}

This is my model class

// Root myDeserializedClass = JsonSerializer.Deserialize<Root>(myJsonResponse);
public class _249130
{
    [JsonPropertyName("success")]
    public bool Success;

    [JsonPropertyName("data")]
    public Data Data;
}

public class Achievements
{
    [JsonPropertyName("total")]
    public int Total;

    [JsonPropertyName("highlighted")]
    public List<Highlighted> Highlighted;
}

public class Category
{
    [JsonPropertyName("id")]
    public int Id;

    [JsonPropertyName("description")]
    public string Description;
}

public class ContentDescriptors
{
    [JsonPropertyName("ids")]
    public List<object> Ids;

    [JsonPropertyName("notes")]
    public object Notes;
}

public class Data
{
    [JsonPropertyName("type")]
    public string Type;

    [JsonPropertyName("name")]
    public string Name;

    [JsonPropertyName("steam_appid")]
    public int SteamAppid;

    [JsonPropertyName("required_age")]
    public int RequiredAge;

    [JsonPropertyName("is_free")]
    public bool IsFree;

    [JsonPropertyName("controller_support")]
    public string ControllerSupport;

    [JsonPropertyName("dlc")]
    public List<int> Dlc;

    [JsonPropertyName("detailed_description")]
    public string DetailedDescription;

    [JsonPropertyName("about_the_game")]
    public string AboutTheGame;

    [JsonPropertyName("short_description")]
    public string ShortDescription;

    [JsonPropertyName("supported_languages")]
    public string SupportedLanguages;

    [JsonPropertyName("header_image")]
    public string HeaderImage;

    [JsonPropertyName("website")]
    public string Website;

    [JsonPropertyName("pc_requirements")]
    public PcRequirements PcRequirements;

    [JsonPropertyName("mac_requirements")]
    public MacRequirements MacRequirements;

    [JsonPropertyName("linux_requirements")]
    public List<object> LinuxRequirements;

    [JsonPropertyName("legal_notice")]
    public string LegalNotice;

    [JsonPropertyName("developers")]
    public List<string> Developers;

    [JsonPropertyName("publishers")]
    public List<string> Publishers;

    [JsonPropertyName("price_overview")]
    public PriceOverview PriceOverview;

    [JsonPropertyName("packages")]
    public List<int> Packages;

    [JsonPropertyName("package_groups")]
    public List<PackageGroup> PackageGroups;

    [JsonPropertyName("platforms")]
    public Platforms Platforms;

    [JsonPropertyName("metacritic")]
    public Metacritic Metacritic;

    [JsonPropertyName("categories")]
    public List<Category> Categories;

    [JsonPropertyName("genres")]
    public List<Genre> Genres;

    [JsonPropertyName("screenshots")]
    public List<Screenshot> Screenshots;

    [JsonPropertyName("movies")]
    public List<Movie> Movies;

    [JsonPropertyName("recommendations")]
    public Recommendations Recommendations;

    [JsonPropertyName("achievements")]
    public Achievements Achievements;

    [JsonPropertyName("release_date")]
    public ReleaseDate ReleaseDate;

    [JsonPropertyName("support_info")]
    public SupportInfo SupportInfo;

    [JsonPropertyName("background")]
    public string Background;

    [JsonPropertyName("background_raw")]
    public string BackgroundRaw;

    [JsonPropertyName("content_descriptors")]
    public ContentDescriptors ContentDescriptors;
}

public class Genre
{
    [JsonPropertyName("id")]
    public string Id;

    [JsonPropertyName("description")]
    public string Description;
}

public class Highlighted
{
    [JsonPropertyName("name")]
    public string Name;

    [JsonPropertyName("path")]
    public string Path;
}

public class MacRequirements
{
    [JsonPropertyName("minimum")]
    public string Minimum;

    [JsonPropertyName("recommended")]
    public string Recommended;
}

public class Metacritic
{
    [JsonPropertyName("score")]
    public int Score;

    [JsonPropertyName("url")]
    public string Url;
}

public class Movie
{
    [JsonPropertyName("id")]
    public int Id;

    [JsonPropertyName("name")]
    public string Name;

    [JsonPropertyName("thumbnail")]
    public string Thumbnail;

    [JsonPropertyName("webm")]
    public Webm Webm;

    [JsonPropertyName("mp4")]
    public Mp4 Mp4;

    [JsonPropertyName("highlight")]
    public bool Highlight;
}

public class Mp4
{
    [JsonPropertyName("480")]
    public string _480;

    [JsonPropertyName("max")]
    public string Max;
}

public class PackageGroup
{
    [JsonPropertyName("name")]
    public string Name;

    [JsonPropertyName("title")]
    public string Title;

    [JsonPropertyName("description")]
    public string Description;

    [JsonPropertyName("selection_text")]
    public string SelectionText;

    [JsonPropertyName("save_text")]
    public string SaveText;

    [JsonPropertyName("display_type")]
    public int DisplayType;

    [JsonPropertyName("is_recurring_subscription")]
    public string IsRecurringSubscription;

    [JsonPropertyName("subs")]
    public List<Sub> Subs;
}

public class PcRequirements
{
    [JsonPropertyName("minimum")]
    public string Minimum;

    [JsonPropertyName("recommended")]
    public string Recommended;
}

public class Platforms
{
    [JsonPropertyName("windows")]
    public bool Windows;

    [JsonPropertyName("mac")]
    public bool Mac;

    [JsonPropertyName("linux")]
    public bool Linux;
}

public class PriceOverview
{
    [JsonPropertyName("currency")]
    public string Currency;

    [JsonPropertyName("initial")]
    public int Initial;

    [JsonPropertyName("final")]
    public int Final;

    [JsonPropertyName("discount_percent")]
    public int DiscountPercent;

    [JsonPropertyName("initial_formatted")]
    public string InitialFormatted;

    [JsonPropertyName("final_formatted")]
    public string FinalFormatted;
}

public class Recommendations
{
    [JsonPropertyName("total")]
    public int Total;
}

public class ReleaseDate
{
    [JsonPropertyName("coming_soon")]
    public bool ComingSoon;

    [JsonPropertyName("date")]
    public string Date;
}

public class Root
{
    [JsonPropertyName("249130")]
    public _249130 _249130;
}

public class Screenshot
{
    [JsonPropertyName("id")]
    public int Id;

    [JsonPropertyName("path_thumbnail")]
    public string PathThumbnail;

    [JsonPropertyName("path_full")]
    public string PathFull;
}

public class Sub
{
    [JsonPropertyName("packageid")]
    public int Packageid;

    [JsonPropertyName("percent_savings_text")]
    public string PercentSavingsText;

    [JsonPropertyName("percent_savings")]
    public int PercentSavings;

    [JsonPropertyName("option_text")]
    public string OptionText;

    [JsonPropertyName("option_description")]
    public string OptionDescription;

    [JsonPropertyName("can_get_free_license")]
    public string CanGetFreeLicense;

    [JsonPropertyName("is_free_license")]
    public bool IsFreeLicense;

    [JsonPropertyName("price_in_cents_with_discount")]
    public int PriceInCentsWithDiscount;
}

public class SupportInfo
{
    [JsonPropertyName("url")]
    public string Url;

    [JsonPropertyName("email")]
    public string Email;
}

public class Webm
{
    [JsonPropertyName("480")]
    public string _480;

    [JsonPropertyName("max")]
    public string Max;
}

CodePudding user response:

You have a bug in your classes, all properties should have getters/ setters, for example

public class _249130
{
    [JsonPropertyName("success")]
    public bool Success {get; set;}

    [JsonPropertyName("data")]
    public Data Data {get; set;}
}

in this case you have to use Text.Json

var result = System.Text.Json.JsonSerializer.Deserialize<Root>(json);

if you want to use Newtonsoft.Json your property attributes should be

public class _249130
{
    [JsonProperty("success")]
    public bool Success;

    [JsonProperty("data")]
    public Data Data ;
}

and code

var result = JsonConvert.DeserializeObject<Root>(json);

When you use Newtonsoft.Json you may leave getters /setters but I higly recommend you to use them

public class _249130
{
    [JsonProperty("success")]
    public bool Success { get; set; }

    [JsonProperty("data")]
    public Data Data  { get; set; }
}
  • Related