JSON.NET序列化/反序列化派生类型? [英] Json.net serialize/deserialize derived types?
问题描述
json.net(newtonsoft)结果
我期待通过的文件,但我不能找到这样的东西,或者做的最好办法。
json.net (newtonsoft)
I am looking through the documentation but I can't find anything on this or the best way to do it.
public class Base
{
public string Name;
}
public class Derived : Base
{
public string Something;
}
JsonConvert.Deserialize<List<Base>>(text);
在序列化列表现在我已经派生的对象。我如何反序列化的列表,并取回派生类型?
Now I have Derived objects in the serialized list. How do I deserialize the list and get back derived types?
推荐答案
如果你是存储在类型的文本
(正如您应该在这种情况下),你可以使用 JsonSerializerSettings
。
If you are storing the type in your text
(as you should be in this scenario), you can use the JsonSerializerSettings
.
请参阅:<一href=\"http://stackoverflow.com/questions/6348215/how-to-deserialize-json-into-ienumerablebasetype-with-newtonsoft-json-net\">how反序列化JSON到了IEnumerable&LT;&BASETYPE GT;与Newtonsoft JSON.NET
这篇关于JSON.NET序列化/反序列化派生类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!