如何将json反序列化为包含接口/抽象类属性的c#类

时间:2022-09-02 11:59:13

I have a model that has a few properties one is an interface and one is abstract base class. I have control of the server and client code. Is there a way to deserialize the json into my model? I have been using the JavaScriptSerializer class for encoding and decoding so a solution there would be nice but it doesnt have to be

我有一个具有一些属性的模型,一个是接口,一个是抽象基类。我控制了服务器和客户端代码。有没有办法将json反序列化到我的模型中?我一直在使用JavaScriptSerializer类进行编码和解码,因此解决方案会很好但不一定非常

1 个解决方案

#1


1  

You cannot have an instance of an abstract class so you can deserialize only to non abstract class, for example a derived class.

您不能拥有抽象类的实例,因此您只能反序列化为非抽象类,例如派生类。

#1


1  

You cannot have an instance of an abstract class so you can deserialize only to non abstract class, for example a derived class.

您不能拥有抽象类的实例,因此您只能反序列化为非抽象类,例如派生类。