我有一个JSON对象,它是一个看起来像这样的字符串数组。它位于一个名为“researchTerms”的变量中:
[{"1":"ifn","2":7,"3":1.81818181818182},{"1":"macrophages","2":5,"3":1.2987012987013},{"1":"n =","2":5,"3":1.2987012987013},{"1":"p <","2":5,"3":1.2987012987013},{"1":"technique","2":5,"3":1.2987012987013},{"1":"cells","2":4,"3":1.03896103896104}]
如何在C#中使用Newtonsoft将其反序列化为一个ResearchTerms数组,其中属性“1”为Term,属性“2”为Count,属性“3”为Score?:
public class ResearchTerm
{
public string Term { get; set; }
public int Count { get; set; }
public long Score { get; set; }
}
答案 0 :(得分:2)
如果您使用的是Json.Net,则可以使用属性 JsonProperty
public class ResearchTerm
{
[JsonProperty("1")]
public string Term { get; set; }
[JsonProperty("2")]
public int Count { get; set; }
[JsonProperty("3")]
public decimal Score { get; set; }
}