Help parsing JSON with Json.NET

Question:

There is the following Json:

{
"status":"ok",
"count":1,
"data":{
    **"1"**:{
        "members_count":100,
        "description":"Закрытый клан, в состав которого входят _лишь_ разработчики игры "World of Tanks". Заявки, посланные командиру клана через форум, _НЕ РАССМАТРИВАЮТСЯ_ . ",
        "description_html":"<p>Закрытый клан, в состав которого входят _лишь_ разработчики игры "World of Tanks".</p><p></p><p>Заявки, посланные командиру клана через форум, _НЕ РАССМАТРИВАЮТСЯ_ . </p>",
        "created_at":1293024672,
        "request_availability":false,
        "updated_at":1381187704,
        "private":null,
        "abbreviation":"WG",
        "emblems":{
            "large":"http://clans.worldoftanks.ru/media/clans/emblems/clans_1/1/emblem_64x64.png",
            "small":"http://clans.worldoftanks.ru/media/clans/emblems/clans_1/1/emblem_24x24.png",
            "bw_tank":"http://clans.worldoftanks.ru/media/clans/emblems/clans_1/1/emblem_64x64_tank.png",
            "medium":"http://clans.worldoftanks.ru/media/clans/emblems/clans_1/1/emblem_32x32.png"
        },
        "clan_id":1,
        "members":{
            **"196632"**:{
                "account_id":196632,
                "created_at":1293126248,
                "updated_at":0,
                "account_name":"Wrobel",
                "role":"private",
                "role_i18n":{
                    "ru":"солдат",
                    "fr":"Soldat",
                    "en":"Soldier",
                    "th":"ทหาร",
                    "vi":"Quân nhân",
                    "de":"Schütze",
                    "tr":"Asker",
                    "it":"солдат",
                    "hu":"солдат",
                    "zh-cn":"战士",
                    "pl":"żołnierz",
                    "ms":"солдат",
                    "cs":"Voják",
                    "es":"Soldado"
                }
            },
            "18458":{
                "account_id":18458,
                "created_at":1360836543,
                "updated_at":0,
                "account_name":"alienraven",
                "role":"diplomat",
                "role_i18n":{
                    "ru":"дипломат",
                    "fr":"Diplomate",
                    "en":"Diplomat",
                    "th":"ทูต",
                    "vi":"ngoại giao",
                    "de":"Diplomat",
                    "tr":"Diplomat",
                    "it":"дипломат",
                    "hu":"дипломат",
                    "zh-cn":"外交官",
                    "pl":"dyplomata",
                    "ms":"дипломат",
                    "cs":"Diplomat",
                    "es":"Diplomático"
                }
            },

There was a problem with the class description for newtown json. there are keys("1","196632") that have non-static names ("1","196632"). Their names change depending on which id I am accessing through the API.

[JsonObject(MemberSerialization.OptIn)]
public class Clan
{
    [JsonProperty("status")]
    public string Status { get; set; }
    [JsonProperty("count")]
    public int Count { get; set; }
    public Data Data { get; set; }
}
[JsonObject(MemberSerialization.OptIn)]
public class Data
{
    //[JsonProperty("что писать вместо 1")]
    //public что писать вместо 1 { get; set; }
}

Answer:

Such jsons can be deserialized into a Dictionary. Here's a highly simplified example:

public class TestClass
{
    public const string Json = @"{""Name"":""Foo"",Bs:{""100"":{""Value"":1,""Flag"":false},""500"":{""Value"":2,""Flag"":true}}}";

    [Test]
    public void Test()
    {
        var a = JsonConvert.DeserializeObject<A>(Json);
    }
}

public class A
{
    public string Name { get; set; }
    public Dictionary<string, B> Bs { get; set; }
}

public class B
{
    public int Value { get; set; }
    public bool Flag { get; set; }
}
Scroll to Top