给出以下JSON:
[
{
"$id": "1",
"$type": "MyAssembly.ClassA, MyAssembly",
"Email": "me@here.com",
},
{
"$id": "2",
"$type": "MyAssembly.ClassB, MyAssembly",
"Email": "me@here.com",
}
]
这些类:
public abstract class BaseClass
{
public string Email;
}
public class ClassA : BaseClass
{
}
public class ClassB : BaseClass
{
}
如何将JSON反序列化为:
IEnumerable<BaseClass> deserialized;
我不能使用,JsonConvert.Deserialize<IEnumerable<BaseClass>>()
因为它抱怨BaseClass
很抽象。
$type
是什么吗?我发现了很多例子,但没有解释。为什么需要先指定MyAssembly. ClassA
然后再指定MyAssembly
?链接的TypeNameHandling
页面也没有提供任何关于此谜的解释:(