-1

Faced such problem:

I have here such answer of JSON and this tree for me too difficult, I need to draw only some objects of icon_url and icon_url_large. Whether it is obligatory to deserializate all JSON for this purpose. Help to sort to me this tree. Thx.

    {
    "result": {
        "230968023": {
            "icon_url": "W_I_5GLm4wPcv9jJQ7z7tz_l_0sEIYUhRfbF4arNQkgGQGKd3kMuVpMgCwRZrg-fckaVmPtFa-_fPQY2FZOxF0a-NaiPx0vyWoYQIoc0bz9AhIzrg00QBijXDLdCANArvs-Shwy5Dh3RJ2URl3QA-A",
            "icon_url_large": "W_I_5GLm4wPcv9jJQ7z7tz_l_0sEIYUhRfbF4arNQkgGQGKd3kMuVpMgCwRZrg-fckaVmPtFa-_fPQY2FZPASkWvM6jDw0v0XohCf9Y8bj4b3dm9gxsTXHDSDeAXXIEjvMmShgrtCVeZfDA-n5JB3KTzdw2wPA",
            "icon_drag_url": "",
            "name": "Inscribed Whalehook",
            "market_hash_name": "Inscribed Whalehook",
            "market_name": "Inscribed Whalehook",
            "name_color": "CF6A32",
            "background_color": "",
            "type": "Immortal weapon",
            "tradable": "1",
            "marketable": "1",
            "commodity": "0",
            "market_tradable_restriction": "7",
            "market_marketable_restriction": "7",
            "fraudwarnings": "",
            "descriptions": {
                "0": {
                    "type": "html",
                    "value": "Used By: Pudge",
                    "app_data": ""
                },
                "1": {
                    "type": "html",
                    "value": "Ideally, a hook made for reeling in enormous creatures of the deep would not gouge and hack into the bones and flesh of the prey. But Pudge doesn't much care if he makes a mess of his meat.",
                    "app_data": ""
                }
            },
            "tags": {
                "0": {
                    "internal_name": "strange",
                    "name": "Inscribed",
                    "category": "Quality",
                    "color": "CF6A32",
                    "category_name": "Quality"
                },
                "1": {
                    "internal_name": "Rarity_Immortal",
                    "name": "Immortal",
                    "category": "Rarity",
                    "color": "e4ae39",
                    "category_name": "Rarity"
                },
                "2": {
                    "internal_name": "wearable",
                    "name": "Wearable",
                    "category": "Type",
                    "category_name": "Type"
                },
                "3": {
                    "internal_name": "weapon",
                    "name": "Weapon",
                    "category": "Slot",
                    "category_name": "Slot"
                },
                "4": {
                    "internal_name": "npc_dota_hero_pudge",
                    "name": "Pudge",
                    "category": "Hero",
                    "category_name": "Hero"
                }
            },
            "classid": "230968023"
        },
        "success": true
    }
}

I tried do some classes for deserializate.

        public class ResultSteamApi
    {
        [JsonProperty("result")]
        public List<SteamApiResult> results { get; set; }
    }

    public class SteamApiResult
    {
        public List<SteamApiClassid> classnum { get; set; }

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

    public class SteamApiClassid
    {
        [JsonProperty("icon_url")]
        public string icon_url { get; set; }

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

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

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

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

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

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

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

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

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

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

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

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

        [JsonProperty("market_marketable_restriction")]
        public string mmarket_marketable_restriction { get; set; }

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

        [JsonProperty("descriptions")]
        public List<SteamApiDescriptions> descriptions { get; set; }

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

Or how to get concrete jbject without deserialization

deathnoob
  • 21
  • 6

1 Answers1

0

Ok, deserialization is a bad idea. Just get it from tokens.

JObject j = JObject.Parse(jsonstring);
        string icon_url = (string)j.SelectToken("result.230968023.icon_url");
        string icon_url_large = (string)j.SelectToken("result.230968023.icon_url_large");
        MessageBox.Show(icon_url);

Thx.

deathnoob
  • 21
  • 6
  • You should probably clarify that you're using Json.NET or a similar library - http://www.newtonsoft.com/json – Henry C Jul 22 '15 at 11:22