Print JSON int in the text box

advertisements

I can't seem to correctly map my classes for this json webpage.

 using (var webClient = new System.Net.WebClient())
        {
            var json = webClient.DownloadString(@"https://opskins.com/api/user_api.php?request=GetLowestSalePrices&key=bac6e59d7edf4be1529adf53a1a5f8&appid=295110&contextid=1&names=Skin:+Graffiti+Hunting+Rifle");
            var jsonData = JsonConvert.DeserializeObject<Items>(json);

            richTextBox1.Text = jsonData.SkinGraffitiHuntingRifle.ToString();
        }
    }

{"result":{"appid":295110,"contextid":1,"items":{"Skin: Graffiti Hunting Rifle":11990}}}

class:

public class Rootobject
{
    public Result result { get; set; }
}

public class Result
{
    public int appid { get; set; }
    public int contextid { get; set; }
    public Items items { get; set; }
}

public class Items
{
    public int SkinGraffitiHuntingRifle { get; set; }
}
}

I can't print out the value of the Skin: Graffiti Hunting Rifle into textbox, returns string is 0 because I didn't map it correctly.


I think you meant to use Rootobject when you deserialize. Try this ;

var jsonData = JsonConvert.DeserializeObject<Rootobject>(json);