1

I would like to know which object would correspond to this Json string. Generally I have no trouble, but here the numbers of the key:value pairs are always changing. So for example for the first one "22548421" next time it could be any number so I do not now how to handle that in C#. Thank you for you time.

{
"22548421": [
    {
        "name": "Jayce's Mercenaries",
        "tier": "SILVER",
        "queue": "RANKED_SOLO_5x5",
        "entries": [
            {
                "playerOrTeamId": "22548421",
                "playerOrTeamName": "sifs",
                "division": "III",
                "leaguePoints": 63,
                "wins": 54,
                "losses": 49,
                "isHotStreak": true,
                "isVeteran": false,
                "isFreshBlood": false,
                "isInactive": false
            }
        ]
    }
],
"23380184": [
    {
        "name": "Darius's Blackguards",
        "tier": "GOLD",
        "queue": "RANKED_SOLO_5x5",
        "entries": [
            {
                "playerOrTeamId": "23380184",
                "playerOrTeamName": "pantoflaman13",
                "division": "V",
                "leaguePoints": 19,
                "wins": 135,
                "losses": 130,
                "isHotStreak": false,
                "isVeteran": true,
                "isFreshBlood": false,
                "isInactive": false
            }
        ]
    },
    {
        "name": "Zyra's Giants",
        "tier": "BRONZE",
        "queue": "RANKED_TEAM_3x3",
        "entries": [
            {
                "playerOrTeamId": "TEAM-3e523c50-f197-11e4-8964-782bcb48f791",
                "playerOrTeamName": "C4crew",
                "division": "I",
                "leaguePoints": 0,
                "wins": 4,
                "losses": 1,
                "isHotStreak": false,
                "isVeteran": false,
                "isFreshBlood": false,
                "isInactive": false
            }
        ]
    }
],
"31526913": [
    {
        "name": "Annie's Executioners",
        "tier": "GOLD",
        "queue": "RANKED_SOLO_5x5",
        "entries": [
            {
                "playerOrTeamId": "31526913",
                "playerOrTeamName": "GDK Beshtiwan",
                "division": "V",
                "leaguePoints": 0,
                "wins": 192,
                "losses": 217,
                "isHotStreak": false,
                "isVeteran": true,
                "isFreshBlood": false,
                "isInactive": false
            }
        ]
    },
    {
        "name": "Twitch's Mercenaries",
        "tier": "BRONZE",
        "queue": "RANKED_TEAM_5x5",
        "entries": [
            {
                "playerOrTeamId": "TEAM-50807400-bab5-11e4-b49d-782bcb4d190f",
                "playerOrTeamName": "Get Dunkid",
                "division": "I",
                "leaguePoints": 38,
                "wins": 6,
                "losses": 3,
                "isHotStreak": false,
                "isVeteran": false,
                "isFreshBlood": false,
                "isInactive": false
            }
        ]
    }
],
"33726623": [
    {
        "name": "Akali's Assassins",
        "tier": "SILVER",
        "queue": "RANKED_SOLO_5x5",
        "entries": [
            {
                "playerOrTeamId": "33726623",
                "playerOrTeamName": "MPAMPHS GR 007",
                "division": "III",
                "leaguePoints": 0,
                "wins": 310,
                "losses": 306,
                "isHotStreak": false,
                "isVeteran": true,
                "isFreshBlood": false,
                "isInactive": false
            }
        ]
    }
],
"34887523": [
    {
        "name": "Akali's Gladiators",
        "tier": "SILVER",
        "queue": "RANKED_SOLO_5x5",
        "entries": [
            {
                "playerOrTeamId": "34887523",
                "playerOrTeamName": "karpuzaotselo",
                "division": "III",
                "leaguePoints": 87,
                "wins": 121,
                "losses": 129,
                "isHotStreak": false,
                "isVeteran": true,
                "isFreshBlood": false,
                "isInactive": false
            }
        ]
    }
],
"36432092": [
    {
        "name": "Karthus's Army",
        "tier": "SILVER",
        "queue": "RANKED_SOLO_5x5",
        "entries": [
            {
                "playerOrTeamId": "36432092",
                "playerOrTeamName": "Vol4mens",
                "division": "IV",
                "leaguePoints": 100,
                "wins": 115,
                "losses": 111,
                "isHotStreak": true,
                "isVeteran": false,
                "isFreshBlood": false,
                "isInactive": false,
                "miniSeries": {
                    "target": 2,
                    "wins": 0,
                    "losses": 0,
                    "progress": "NNN"
                }
            }
        ]
    },
    {
        "name": "Nasus's Swarm",
        "tier": "BRONZE",
        "queue": "RANKED_TEAM_3x3",
        "entries": [
            {
                "playerOrTeamId": "TEAM-02ac4070-d166-11e4-aad1-782bcb48f791",
                "playerOrTeamName": "League of Fitness",
                "division": "I",
                "leaguePoints": 12,
                "wins": 5,
                "losses": 4,
                "isHotStreak": false,
                "isVeteran": false,
                "isFreshBlood": false,
                "isInactive": false
            }
        ]
    },
    {
        "name": "Annie's Cutthroats",
        "tier": "BRONZE",
        "queue": "RANKED_TEAM_5x5",
        "entries": [
            {
                "playerOrTeamId": "TEAM-02ac4070-d166-11e4-aad1-782bcb48f791",
                "playerOrTeamName": "League of Fitness",
                "division": "III",
                "leaguePoints": 9,
                "wins": 10,
                "losses": 11,
                "isHotStreak": false,
                "isVeteran": false,
                "isFreshBlood": false,
                "isInactive": false
            }
        ]
    }
],
"41537855": [
    {
        "name": "Sivir's Alliance",
        "tier": "SILVER",
        "queue": "RANKED_SOLO_5x5",
        "entries": [
            {
                "playerOrTeamId": "41537855",
                "playerOrTeamName": "My name is daka",
                "division": "II",
                "leaguePoints": 57,
                "wins": 159,
                "losses": 169,
                "isHotStreak": false,
                "isVeteran": true,
                "isFreshBlood": false,
                "isInactive": false
            }
        ]
    }
],
"42498193": [
    {
        "name": "Viktor's Marauders",
        "tier": "SILVER",
        "queue": "RANKED_SOLO_5x5",
        "entries": [
            {
                "playerOrTeamId": "42498193",
                "playerOrTeamName": "Exspy",
                "division": "II",
                "leaguePoints": 100,
                "wins": 288,
                "losses": 296,
                "isHotStreak": true,
                "isVeteran": true,
                "isFreshBlood": false,
                "isInactive": false,
                "miniSeries": {
                    "target": 2,
                    "wins": 1,
                    "losses": 0,
                    "progress": "WNN"
                }
            }
        ]
    },
    {
        "name": "Nasus's Swarm",
        "tier": "BRONZE",
        "queue": "RANKED_TEAM_3x3",
        "entries": [
            {
                "playerOrTeamId": "TEAM-02ac4070-d166-11e4-aad1-782bcb48f791",
                "playerOrTeamName": "League of Fitness",
                "division": "I",
                "leaguePoints": 12,
                "wins": 5,
                "losses": 4,
                "isHotStreak": false,
                "isVeteran": false,
                "isFreshBlood": false,
                "isInactive": false
            }
        ]
    },
    {
        "name": "Annie's Cutthroats",
        "tier": "BRONZE",
        "queue": "RANKED_TEAM_5x5",
        "entries": [
            {
                "playerOrTeamId": "TEAM-02ac4070-d166-11e4-aad1-782bcb48f791",
                "playerOrTeamName": "League of Fitness",
                "division": "III",
                "leaguePoints": 9,
                "wins": 10,
                "losses": 11,
                "isHotStreak": false,
                "isVeteran": false,
                "isFreshBlood": false,
                "isInactive": false
            }
        ]
    },
    {
        "name": "Dr. Mundo's Tyrants",
        "tier": "BRONZE",
        "queue": "RANKED_TEAM_3x3",
        "entries": [
            {
                "playerOrTeamId": "TEAM-155bf680-0798-11e5-8e2b-782bcb46f3e4",
                "playerOrTeamName": "KokaKlucisKonstantins",
                "division": "II",
                "leaguePoints": 33,
                "wins": 5,
                "losses": 5,
                "isHotStreak": false,
                "isVeteran": false,
                "isFreshBlood": false,
                "isInactive": false
            }
        ]
    },
    {
        "name": "Rengar's Warlords",
        "tier": "BRONZE",
        "queue": "RANKED_TEAM_5x5",
        "entries": [
            {
                "playerOrTeamId": "TEAM-155bf680-0798-11e5-8e2b-782bcb46f3e4",
                "playerOrTeamName": "KokaKlucisKonstantins",
                "division": "II",
                "leaguePoints": 21,
                "wins": 8,
                "losses": 5,
                "isHotStreak": false,
                "isVeteran": false,
                "isFreshBlood": false,
                "isInactive": false
            }
        ]
    }
],
"43463467": [
    {
        "name": "Janna's Runemasters",
        "tier": "SILVER",
        "queue": "RANKED_SOLO_5x5",
        "entries": [
            {
                "playerOrTeamId": "43463467",
                "playerOrTeamName": "I luv Expoil",
                "division": "III",
                "leaguePoints": 100,
                "wins": 213,
                "losses": 237,
                "isHotStreak": false,
                "isVeteran": true,
                "isFreshBlood": false,
                "isInactive": false,
                "miniSeries": {
                    "target": 2,
                    "wins": 1,
                    "losses": 0,
                    "progress": "WNN"
                }
            }
        ]
    }
],
"52665047": [
    {
        "name": "LeBlanc's Duelists",
        "tier": "SILVER",
        "queue": "RANKED_SOLO_5x5",
        "entries": [
            {
                "playerOrTeamId": "52665047",
                "playerOrTeamName": "Megoldom",
                "division": "II",
                "leaguePoints": 65,
                "wins": 204,
                "losses": 213,
                "isHotStreak": false,
                "isVeteran": true,
                "isFreshBlood": false,
                "isInactive": false
            }
        ]
    },
    {
        "name": "Nami's Weaponmasters",
        "tier": "BRONZE",
        "queue": "RANKED_TEAM_5x5",
        "entries": [
            {
                "playerOrTeamId": "TEAM-c0b583f0-2f18-11e5-91f0-782bcb4d190f",
                "playerOrTeamName": "TeamThugLifes",
                "division": "IV",
                "leaguePoints": 0,
                "wins": 3,
                "losses": 2,
                "isHotStreak": false,
                "isVeteran": false,
                "isFreshBlood": false,
                "isInactive": false
            }
        ]
    }
]

}

2
  • where did you get this json? Commented Aug 9, 2015 at 4:19
  • It's from the League of Legends API. Commented Aug 9, 2015 at 12:20

1 Answer 1

2

Newtonsoft.Json does the job wonderfully. The only thing is that this scenario is not common :)

Below is the code of the Json Structure

 [JsonDictionary]
public class JsonClass : Dictionary<string, List<PlayerClass>>
{
}

public class PlayerClass
{
    public string name { get; set; }
    public string tier { get; set; }
    public string queue { get; set; }
    public List<PlayerDetails> entries { get; set; }
}

public class PlayerDetails
{
    public string playerOrTeamId { get; set; }
    public string playerOrTeamName { get; set; }
    public string division { get; set; }
    public long leaguePoints { get; set; }
    public long wins { get; set; }
    public long losses { get; set; }
    public bool isHotStreak { get; set; }
    public bool isVeteran { get; set; }
    public bool isFreshBlood { get; set; }
    public bool isInactive { get; set; }
}

You can just use two lines of code to deserialize it

string jsonString = new StreamReader(File.Open("TextFile1.json", FileMode.Open)).ReadToEnd();
var deserializedOutput = JsonConvert.DeserializeObject<JsonClass>(jsonString);

where TextFile1.json is a file which contains your json

Below is the deserialized output

enter image description here

PS: I Used version 7.0.1 of Newtonsoft.Json nuget package

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.