-1

クラスをシリアル化してwith Newtonsoft.Json.JsonConvert.SerializeObject 空のリストを null 変数に変更する方法

連載の結果

{"images":[]} or {"images":{}}

取得したい

{"images":null}

私の簡単なクラス

public class Images
{
[JsonProperty("images", Required = Required.Always, NullValueHandling = NullValueHandling.Include)]

   public Images()
   {
   Parameters = new Parameters(); **//  I know I could not initiate here only when I need it but I don't want to do it**
   }

   [JsonProperty("parameters", Required = Required.Always, NullValueHandling = NullValueHandling.Include)]
   public Parameters Parameters { get; set; }
}

public class Parameters 
{
   [JsonProperty("id", Required = Required.AllowNull, NullValueHandling = NullValueHandling.Include)]
   public string Id { get; set; }
}
4

1 に答える 1