To serialize an object, but if the property of the object is null, we want to remove the property as null, how to deal with it? In fact, the method is very simple, following the script of the small part of Learning C # Json serialization to remove the null value of the method bar
To serialize an object, but if the object's property is null, we want to remove the property as null.
Here I useNewtonsoft.Json.dll
Record serialization and deserialization
JSON string Goto Object
Model model=jsonconvert.deserializeobject<model> (Val);
Convert an object to a JSON-formatted string
String jsonstring = Jsonconvert.serializeobject (obj);
So how to filter out NULL when serializing JSON??
var jsonsetting = new Jsonserializersettings {nullvaluehandling = Nullvaluehandling.ignore};var json = Jsonconvert.serializeobject (data, formatting.indented, jsonsetting);
JsonConvert.SerializeObject(obj);
serialization of results directly
"Memberquery": { "PhoneNumber": "13222222222", "Name": "Test", "MF": "Female", "BirthDate": "01/01/2017" , "maritalstatus": null, "country": null}
Filter out NULL serialization results:
"Memberquery": {"PhoneNumber": "13222222222", "Name": "Test", "MF": "Female", "BirthDate": "01/01/2017"}
Summarize