我正在使用Newtonsoft.Json.JsonConvert
将Textbox
(WinForms)序列化为 json,并且我希望序列化跳过具有默认值或空数组的属性。
我尝试使用NullValueHandling = NullValueHandling.Ignore
inJsonSerializerSettings
但似乎没有任何影响。
这是完整的代码示例(简化):
JsonSerializerSettings settings = new JsonSerializerSettings()
{
Formatting = Formatting.None,
DefaultValueHandling = DefaultValueHandling.Ignore,
NullValueHandling = NullValueHandling.Ignore,
ReferenceLoopHandling = ReferenceLoopHandling.Ignore,
ObjectCreationHandling = ObjectCreationHandling.Replace,
PreserveReferencesHandling = PreserveReferencesHandling.None,
ConstructorHandling = ConstructorHandling.AllowNonPublicDefaultConstructor,
};
string json = JsonConvert.SerializeObject(textbox, settings);
有任何想法吗 ?