我正在尝试解析以以下结构返回给我的JSON,但是我只是无法正确获取该类的结构才能正确解析:
{"44542152": [{
"queue": "RANKED_SOLO_5x5",
"name": "Elise's Elite",
"entries": [{
"leaguePoints": 0,
"isFreshBlood": false,
"isHotStreak": false,
"division": "IV",
"isInactive": false,
"isVeteran": false,
"playerOrTeamName": "Autdsm",
"playerOrTeamId": "44543152",
"wins": 11
}],
"tier": "SILVER"
}]}
但是由于JSON的“ 44542152”:根部会根据我请求的用户而变化,因此我很难将其解析为一个对象。
这是我到目前为止所拥有的:
public static AreTheyChallenger.Core.RankInfo getLeague(string region, Summoner summoner)
{
try
{
using (var webClient = new WebClient())
{
var json = webClient.DownloadString("https://" + region + ".api.pvp.net/api/lol/" + region + "/v2.5/league/by-summoner/" + summoner.id + "/entry" + "?api_key=" + Keys.api_key);
var summonerRankInfo = JObject.Parse(json).Values().First().ToObject<RankInfo>();
return summonerRankInfo;
}
}
catch (Exception e)
{
Console.WriteLine(e);
}
return null;
}
这是我正在尝试将其解析为的类:
public class RankInfo
{
public class Entry
{
public int leaguePoints { get; set; }
public bool isFreshBlood { get; set; }
public bool isHotStreak { get; set; }
public string division { get; set; }
public bool isInactive { get; set; }
public bool isVeteran { get; set; }
public string playerOrTeamName { get; set; }
public string playerOrTeamId { get; set; }
public int wins { get; set; }
}
public class RootObject
{
public string queue { get; set; }
public string name { get; set; }
public List<Entry> entries { get; set; }
public string tier { get; set; }
}
}
我对此很陌生,因此很抱歉如果问题很明显,但是我的目的是能够访问一些存储的属性并将其呈现给用户。
提前致谢。
你很亲密
那应该是您的演员表中的RootObject []。再次查看您的JSON ...如果正确缩进它会更有帮助。它将字符串映射到对象数组,而不是单个对象,这些对象是RootObject,而不是RankInfo。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句