Can JavaScriptSerializer exclude properties with null/default values?

前端 未结 7 1155
野趣味
野趣味 2020-12-01 05:08

I\'m using JavaScriptSerializer to serialize some entity objects.

The problem is, many of the public properties contain null or default values. Is there any way to m

7条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-01 05:47

    For the benefit of those who find this on google, note that nulls can be skipped natively during serialization with Newtonsoft.Json

    var json = JsonConvert.SerializeObject(
                objectToSerialize,
                new JsonSerializerSettings {NullValueHandling = NullValueHandling.Ignore});
    

提交回复
热议问题