I am using DataContractJsonSerializer
to serialize my custom object to JSON. But i want to skip the data members whose values are null
. If DataMember
is null
that node should not come in JSON string.
How can I achieve this? Give me a simple code snippet
to work with.
You can use the
EmitDefaultValue = false
property in the[DataMember]
attribute. For members marked with that attribute, their values will not be output.