我正在寻找一种使用System.Text.Json序列化对象的方法,但根据其他属性值,某些属性会被忽略。data = new Data Type = "A", B = "data B",}; 当Type值为A时,我想序列化属性当Type值为B时,我希望序列化属性Type、B和BC。 诸若此类。 有没有办法做到这一点?我曾经制作过带自定义<e
我的三层1: model :1 EF数据模型是以多种方式查询的,它可以很好地将JsonIgnore属性应用于某些虚拟属性,以消除引用循环问题。(我在答案中使用了第三个解决方案)是否有任何方法在运行时控制JsonIgnore属性?或者,是否有任何方法可以在运行时在NewtonSoft.JSON中忽略on和off属性?
我试图弄清楚如何为一个值创建一个属性NonSerialized。看看这个:using System.Text.Json;class Test public static bool GoingToBeSerialized} // i want to disable it if GoingToBeSerialized is true
[System.Text.Json.Serialization.JsonIgnore
AddNewtonsoftJson in ConfigureServices似乎什么也不做,而新的Json序列化程序似乎只在属性上工作,而不是字段。它没有看到JSONIgnoreAttribute。在我的应用程序中,只有属性是序列化的,而不是字段,而[JSONIgnore]属性什么也不做。
我可以通过提升所有我需要成为属性的公共字段来解决这些领域的不足,但我需要能够忽略一些。如何使新的JSON序列化程序忽略某些属性并序列化公共字段,或者返回到Newtonsoft?