[英]Deserialize JSON that was serialized with Newtonsoft CamelCasePropertyNamesContractResolver
[英]Property not getting serialized in Json via newtonsoft
类中定义了许多属性,但其中一个属性没有被序列化(使用 newtonsoft),下面提到了该属性:
public override string Value
{
set
{
if (value == null)
{
this.Null = true;
}
else if (value == string.Empty)
{
_A = string.Empty;
_P = string.Empty;
_S = string.Empty;
}
else
{
value = _A + _P + _S;
}
}
}
但是当我们在属性中定义 getter 时,它会被序列化,所以请提出建议; 我们不想将吸气剂放在属性中。
将[JsonProperty]
属性设置为您的属性。 但总的来说,您可以将您的 getter 设为private
- 这样您就不会将数据暴露给其他类,但它可以帮助解决您的问题。
好吧,首先,您没有 Get how will json now to serialize it,也许使它成为一个方法看起来很有趣,因为它只有一个属性集。 如果你想填充你的字段,只需告诉 json 使用注释来做到这一点
[JsonProperty("_A")]
private string _A ;
[JsonProperty("_P")]
private string _P ;
[JsonProperty("_S")]
private string _S;
[JsonIgnore]
public override string Value
{
set
{
if (value == null)
{
this.Null = true;
}
else if (value == string.Empty)
{
_A = string.Empty;
_P = string.Empty;
_S = string.Empty;
}
else
{
value = _A + _P + _S;
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.