我正在使用 ASP.NET Web API,并且尝试返回如下所示的类的实例:
public class Whatever
{
public int MyInt {get; set;}
public IFoo MyFoo {get; set;}
}
当此实例序列化为 JSON 时,IFoo
成员(可能是实现 IFoo
的任意多个类的实例)会奇怪地序列化。属性名称已写入,但其值是一大块 HTML,其中包含如下错误消息:
You must write an attribute 'type'='object' after writing the attribute with local name '__type'.
这是框架告诉我它不知道如何将实例转换为接口(interface)吗?还是别的什么?
最佳答案
每当框架尝试序列化类型为接口(interface)的成员时,就会出现此错误。除了更改成员以使其类型具体之外,我找不到其他方法来解决此问题。
关于asp.net web api - 接口(interface)成员的 json 序列化导致神秘错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10416877/