J'ai un JSON que, par exemple, ressemble àDeserialize JSON avec des propriétés dynamiques avec JSON.NET en C#
{"historymatch":
{
"id":[1581402],
"mid":[166],
"aid":[5621],
"bid":[18548],
"date":["24/05/16"],
"liveA":[3],
"liveB":[1],
"redA":[0],
"redB":[0],
"bc":["3-0"],
"ng":[0],
"rq":["-1.5"],
"rql":[0],
"worl":[0],
"oworl":[0]},
"match":
{
"166":
{
"n":"INT CF",
"c":"5691D8"
}
},
"team":
{
"5621":"Melbourne Knights",
"18548":"Dandenong City SC"
},
"note":{}
}
Comme vous pouvez le voir, il y a des propriétés dynamiques et sur le terrain en match et en équipe. J'ai essayé de tenir compte dans mes C# cours
class History<T> where T : new()
{
public HistoryMatch<T> HistoryMatch { get; set; }
}
class HistoryMatch<T> where T: new()
{
[JsonProperty("id")]
public IList<long> MatchId { get; set; }
[JsonProperty("mid")]
public IList<long> LeagueId { get; set; }
[JsonProperty("aid")]
public IList<long> TeamAId { get; set; }
[JsonProperty("bid")]
public IList<long> TeamBId { get; set; }
[JsonProperty("date")]
public IList<string> MatchDate { get; set; }
[JsonProperty("liveA")]
public IList<long> TeamAScore { get; set; }
[JsonProperty("liveB")]
public IList<long> TeamBScore { get; set; }
[JsonProperty("redA")]
public IList<long> TeamARedCard { get; set; }
[JsonProperty("redB")]
public IList<long> TeamBRedCard { get; set; }
[JsonProperty("bc")]
public IList<string> HalfTimeScore { get; set; }
[JsonProperty("ng")]
public IList<long> Ng { get; set; }
[JsonProperty("rq")]
public IList<string> Rq { get; set; }
[JsonProperty("rql")]
public IList<long> Rql { get; set; }
[JsonProperty("worl")]
public IList<long> Worl { get; set; }
[JsonProperty("oworl")]
public List<long> Oworl { get; set; }
[JsonProperty("match")]
public Dictionary<string,T> Match { get; set; }
[JsonProperty("team")]
public Team Team { get; set; }
[JsonProperty("note")]
public Note Note { get; set; }
}
class Match
{
[JsonProperty("n")]
public string Name { get; set; }
[JsonProperty("c")]
public string Color { get; set; }
}
class Team
{
public Dictionary<string, string> Values { get; set; }
}
class Note
{
}
Je désérialiser la façon
var obj = JsonConvert.DeserializeObject<History<Match>>(responseText);
suivante Il est désérialisée sans erreur, mais les attributs Match
et Team
de la classe HistoryMatch
sont null
après . J'ai pris plusieurs tentatives maintenant mais il me semble qu'il me manque quelque chose d'essentiel ici. Quelqu'un pourrait-il me donner un conseil s'il vous plaît?
Vous avez raison! Merde, j'ai été dérouté par les crochets ouverts et fermés. Merci de votre aide – lichtbringer