2

I'm having quite an issue with converting this json to c# due to the fact that the object holding all the data I need is a dynamic property and I can't just define a class that holds all the property values as I've been doing. Sample json is below, any ideas for extracting the data from the "144038410" object? I appreciate any guidance on this issue.

{
"result": {
    "144038410": {
        "icon_url": "W_I_5GLm4wPcv9jJQ7z7tz_l_0sEIYUhRfbF4arNQkgGQGKd3kMuVpMgCwRZrhyFY1OZ0v4CYfbKFzE6FY3tT0Gve6aY1lyeWN9SaN1gKyFN2I3hgUkVXHeDV78TC9V_vJLFhwPrXgeUf2ZpytoBgaXHiZCBWKDVt1K5J0cGAAdo",
        "icon_url_large": "W_I_5GLm4wPcv9jJQ7z7tz_l_0sEIYUhRfbF4arNQkgGQGKd3kMuVpMgCwRZrhyFY1OZ0v4CYfbKFzE6FY3tT0Gve6aY1lyeWN9SaN1gK1AV3Zu_01cXBiPUB7EVXNJ4tczLh1i8BQrEcDs0nt8Ch_Wc0cOCU67VqxbjdgUmzaQ3WoDEBb7J",
        "icon_drag_url": "",
        "name": "Kupu the Metamorpher",
        "market_hash_name": "Kupu the Metamorpher",
        "market_name": "Kupu the Metamorpher",
        "name_color": "D2D2D2",
        "background_color": "",
        "type": "Mythical Kupu Courier",
        "tradable": "1",
        "marketable": "1",
        "commodity": "0",
        "market_tradable_restriction": "7",
        "market_marketable_restriction": "7",
        "fraudwarnings": "",
        "descriptions": {
            "0": {
                "type": "html",
                "value": "All hail Kupu the Metamorpher!  Honest and forthright, Kupu with delivery your items in a most timely fashion.  Steadfast!",
                "app_data": ""
            }
        },
        "tags": {
            "0": {
                "internal_name": "unique",
                "name": "Standard",
                "category": "Quality",
                "color": "D2D2D2",
                "category_name": "Quality"
            },
            "1": {
                "internal_name": "Rarity_Mythical",
                "name": "Mythical",
                "category": "Rarity",
                "color": "8847ff",
                "category_name": "Rarity"
            },
            "2": {
                "internal_name": "courier",
                "name": "Courier",
                "category": "Type",
                "category_name": "Type"
            },
            "3": {
                "internal_name": "courier",
                "name": "Courier",
                "category": "Slot",
                "category_name": "Slot"
            },
            "4": {
                "internal_name": "DOTA_OtherType",
                "name": "Other",
                "category": "Hero",
                "category_name": "Hero"
            }
        },
        "classid": "144038410"
    },
    "success": true
}

}

Symptum
  • 21
  • 1
  • I just got it using the method below, thanks for all the help guys. JObject json = JsonConvert.DeserializeObject(jsonString); var asdf = why["result"].First.First.ToObject(); where POCO is a class holding the attributes I need – Symptum Jul 05 '15 at 12:24

1 Answers1

1

You have to decorate your Formats properties with JsonProperty attributes to tell it what goes where if the name does not exactly match:

partial class result
{
    [JsonProperty("144038410")]
    public dynamic _144038410 {get; set;}
}

See also Using JsonConvert.DeserializeObject to deserialize Json to a C# POCO class

Community
  • 1
  • 1
Ali Adlavaran
  • 3,697
  • 2
  • 23
  • 47
  • I know you can do it this way but the issue is I have roughly 5000 records so I'll have to do this for 5000 different numbers? There has to be a cleaner solution – Symptum Jul 05 '15 at 11:59