Removing entries from json string in C# -
i have json string generated follows:
system.xml.serialization.xmlserializer x = new system.xml.serialization.xmlserializer(typeof(data)); system.runtime.serialization.json.datacontractjsonserializer serializer = new system.runtime.serialization.json.datacontractjsonserializer(mdata.gettype()); memorystream ms = new memorystream(); serializer.writeobject(ms, mdata); string json = encoding.utf8.getstring(ms.toarray()); i want null entries in mdata structure not present in json string there straightforward way (without having parse json string) ?
thanks
you can set datamember attribute option isrequired false:
[datamember(isrequired = false)] public int property { get; set; } also, libraries can exclude default or null values without modifying datacontract classes. example, json.net.
Comments
Post a Comment