包含数组的JSON上的JavaScriptSerializer
本文关键字:上的 JavaScriptSerializer JSON 数组 包含 | 更新日期: 2023-09-27 17:57:34
我有一个JSON字符串,如下所示:
{
"letterstats":[
{"time_taken":636,"mistake_letters":"","the_letter":"L","success":true},
{"time_taken":216,"mistake_letters":"","the_letter":"U","success":true},
{"time_taken":103,"mistake_letters":"","the_letter":"I","success":true}
],
"word":"TEST"
}
我正试图使用JavaScriptSerializer来解析它,但我遇到了一个问题。以下是我用来解析的c#代码:
public class wordStats
{
public string word { get; set; }
List<letterStats> letterstats { get; set; }
public wordStats() { letterstats = new List<letterStats>(); }
}
public class letterStats
{
public int time_taken { get; set; }
public string mistake_letters { get; set; }
public string the_letter { get; set; }
public bool success { get; set; }
}
JavaScriptSerializer ser = new JavaScriptSerializer();
wordStats ws = ser.Deserialize<wordStats>(jsonObj);
它正在解析单词fine("TEST"),但没有解析数组。我不确定发生了什么,我引用这个是为了让它发挥作用。有人知道出了什么问题吗?感谢
letterstats
属性是私有的。
public class wordStats
{
public string word { get; set; }
public List<letterStats> letterstats { get; set; }
}