草庐IT

ItemRequired

全部标签

c# - 使用带有 ItemRequired = Required.Always 的 Json.Net 反序列化时忽略属性

我正在使用Json.Net将类序列化和反序列化为json并返回。我添加到标有[JsonObject(ItemRequired=Required.Always)]的类中(或Required.Always)一个新的只读属性。这导致以下JsonSerializationException:Newtonsoft.Json.JsonSerializationException:Requiredproperty''notfoundinJSON我想用JsonIgnore标记该属性会解决问题,但这不起作用。我如何告诉Json.Net这个属性应该被忽略?这是重现该问题的最小示例:[JsonObject(