1
为什么这个JSON反序列化回它从序列化的模型?它将反序列化到一个Bar列表,而不是实现List列表的对象。问题反序列化JSON回到原始模型
public class Bars : List<Bar>
{
}
public class Bar
{
public decimal Open { get; set; }
public decimal High { get; set; }
public decimal Low { get; set; }
public decimal Close { get; set; }
}
private void test()
{
Bars bars = new Bars()
{
new Bar(){Open = 1.5269M, High = 1.6001M, Low = 1.4012M, Close = 1.5277M},
new Bar(){Open = 1.5277M, High = 1.6003M, Low = 1.5276M, Close = 1.7008M},
new Bar(){Open = 1.7008M, High = 1.9003M, Low = 1.4276M, Close = 1.60098M}
};
JavaScriptSerializer jss = new JavaScriptSerializer();
string json = jss.Serialize(bars);
//works
var dsBars1 = jss.Deserialize<List<Bar>>(json);
//fails
var dsBars2 = jss.Deserialize<Bars>(json);
}