方法一、
单独忽略某个属性。使用
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
引用
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
public IList<RequestpassengerInfo> passenger { get; set; }
/// <summary>
/// 价格信息节点
/// </summary>
public RequestpriceInfo price { get; set; }
/// <summary>
/// 儿童价格信息节点
/// </summary>
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
public RequestchdPriceInfo chdPrice { get; set; }
方法二、
全局忽略。使用
NullValueHandling = NullValueHandling.Ignore
调用JsonConvert.SerializeObject()时使用NullValueHandling.Ignore
string json = JsonConvert.SerializeObject(
Attributes,
Formatting.Indented,
new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore });