Convert only object to JSON string Serialized fields

JavaScriptSerializer serializer = new JavaScriptSerializer(); string sJSON = serializer.Serialize(pt); 

This works fine, except that it also includes fields that are set to [NonSerialized] Is there a way to exclude these fields?

+4
source share
2 answers

[ScriptIgnore()] is what you want

The [NonSerialized()] tag works only for binary serialization, your example is serializing a Java script

+3
source

I think you are looking for ScriptIgnoreAttribute :

 public class Data { [ScriptIgnore] public string Ignore; public string DoNotIgnore; } 
+3
source

All Articles