我想知道哪个对象对应于这个Json字符串。一般来说,我没有遇到任何麻烦,但这里的密钥:值对的数量总是在变化。所以例如对于第一个“22548421”下次它可能是任何数字,所以我现在不知道如何在C#中处理它。谢谢你的时间。
{
"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
}
]
}
]
}
答案 0 :(得分:2)
Newtonsoft.Json完成了这项工作。唯一的问题是这种情况并不常见:)
以下是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; }
}
您可以使用两行代码对其进行反序列化
string jsonString = new StreamReader(File.Open("TextFile1.json", FileMode.Open)).ReadToEnd();
var deserializedOutput = JsonConvert.DeserializeObject<JsonClass>(jsonString);
其中TextFile1.json
是包含json
下面是反序列化的输出
PS:我使用了Newtonsoft.Json nuget包的版本7.0.1