【发布时间】:2020-04-29 08:51:30
【问题描述】:
我有一个基类,具有一个列表作为属性。 我有多个从该类派生的类,我希望在序列化时拥有具有不同名称的这些属性...
如果未在派生对象中指定属性,则 Json.Net 修饰不起作用 如果我指定它,我会收到“如果要隐藏,请使用新关键字”的建议。 ,如果我这样做,我可能会失去财产上的基本程序?
public class Translation
{
[JsonProperty(PropertyName = "name")]
public string Name { get; set; };
[JsonProperty(PropertyName = "translatedCaption")]
public string TranslatedCaption { get; set; };
public List<Translation> Children { get; set; };
public Translation(string name,string translatedCaption)
{
Name=name;
TranslatedCaption=translatedCaption;
Children = new List<Translation>();
}
public void Add(Translation translation)
{
...
}
}
public class Translation_Model : Translation
{
[JsonProperty(PropertyName = "tables")]
public List<Translation> Children { get; set; };
}
【问题讨论】: