【发布时间】:2022-01-04 13:13:25
【问题描述】:
正如标题所暗示的,我有一个多层 json 文件,其中包含很多属性。如果 JsonProperty"use-stepover" 为 false,我需要省略 jsonProperty "stepdown"。
我尝试了 json ignore nullvaluehandling,但该值为 0.0 而不是 null 值,因此无法正常工作。 想知道我是否应该使用 Json 默认值并将其设置为 null
这里有一些代码供那些希望看到它的人使用。最后两个道具就是我在说的。
JSON 类
public partial class Preset
{
[JsonProperty("description")]
public string Description { get; set; }
[JsonProperty("f_n")]
public double? FN { get; set; }
[JsonProperty("f_z")]
public double? FZ { get; set; }
[JsonProperty("guid")]
public Guid Guid { get; set; }
[JsonProperty("n")]
public double N { get; set; }
[JsonProperty("n_ramp")]
public double? NRamp { get; set; }
[JsonProperty("name")]
public string Name { get; set; }
[JsonProperty("tool-coolant")]
public string ToolCoolant { get; set; }
[JsonProperty("use-stepdown")]
public bool UseStepdown { get; set; }
[JsonProperty("use-stepover")]
public bool UseStepover { get; set; }
[JsonProperty("v_c")]
public double VC { get; set; }
[JsonProperty("v_f")]
public double? VF { get; set; }
[JsonProperty("v_f_leadIn")]
public double? VFLeadIn { get; set; }
[JsonProperty("v_f_leadOut")]
public double VFLeadOut { get; set; }
[JsonProperty("v_f_plunge")]
public double VFPlunge { get; set; }
[JsonProperty("v_f_ramp")]
public double VFRamp { get; set; }
[JsonProperty("v_f_retract")]
public double VFRetract { get; set; }
[JsonProperty("stepdown", NullValueHandling = NullValueHandling.Ignore)]
public double Stepdown { get; set; }
[JsonProperty("stepover", NullValueHandling = NullValueHandling.Ignore)]
public double Stepover { get; set; }
}
【问题讨论】: