[英]Json issue in a sub-class
I have 2 DTO files, with one of them being a sub-class of the other. 我有2个DTO文件,其中一个是另一个的子类。 The fields on the super-class are as follows: 超类上的字段如下:
[JsonProperty]
protected int financialFormatHeaderID;
[JsonProperty]
protected string financialFormatHeaderCode;
[JsonProperty]
protected string description = string.Empty;
[JsonProperty]
protected FinancialFormatPurpose purpose = FinancialFormatPurpose.Standard;
[JsonProperty]
protected IList<FinancialFormatDetailDto> details = new List<FinancialFormatDetailDto>();
[JsonProperty]
protected bool active = true;
The sub-class has this: 子类具有以下内容:
public RecoveryFormatHeaderDto()
: base() {
this.purpose = FinancialFormatPurpose.Recovery;
}
[JsonProperty]
private bool isPerSquareArea;
They both have the JsonObject(MemberSerialization.OptIn) and Serializable attributes above the class name (but under the namespace). 它们都在类名上方(但在名称空间下)具有JsonObject(MemberSerialization.OptIn)和Serializable属性。
My problem is that when I try to save an instance of the sub-class I get the following error: 我的问题是,当我尝试保存子类的实例时,出现以下错误:
Newtonsoft.Json.JsonSerializationException was unhandled by user code 用户代码未处理Newtonsoft.Json.JsonSerializationException
Message=A member with the name 'financialFormatHeaderID' already exists on 'RecoveryFormatHeaderDto'. 消息=名称为'financialFormatHeaderID'的成员已经存在于'RecoveryFormatHeaderDto'上。 Use the JsonPropertyAttribute to specify another name. 使用JsonPropertyAttribute指定另一个名称。
Source=Newtonsoft.Json 资料来源= Newtonsoft.Json
What is happening here? 这是怎么回事 How do I fix this? 我该如何解决?
EDIT: Class signatures are as follows: 编辑:类签名如下:
public class FinancialFormatHeaderDto
public class RecoveryFormatHeaderDto : FinancialFormatHeaderDto
Though I don't know Json.Net, my guess would be that the problem is somewhat related to that you have the JsonObjectAttribute(MemberSerialization.OptIn) on both classes. 尽管我不了解Json.Net,但我的猜测是问题与在两个类上都有JsonObjectAttribute(MemberSerialization.OptIn)有关。 Perhaps you should try removing that attribute from the sub-class, and see if it helps. 也许您应该尝试从子类中删除该属性,然后查看是否有帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.