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?
[NonSerialized]
[ScriptIgnore()] is what you want
[ScriptIgnore()]
The [NonSerialized()] tag works only for binary serialization, your example is serializing a Java script
[NonSerialized()]
I think you are looking for ScriptIgnoreAttribute :
ScriptIgnoreAttribute
public class Data { [ScriptIgnore] public string Ignore; public string DoNotIgnore; }