Reputation: 735
JavaScriptSerializer serializer = new JavaScriptSerializer();
string sJSON = serializer.Serialize(pt);
This works fine except that it also includes fields that are set as [NonSerialized]
Is there a way to exclude those fields?
Upvotes: 4
Views: 423
Reputation: 726599
I think you are looking for the ScriptIgnoreAttribute
:
public class Data {
[ScriptIgnore]
public string Ignore;
public string DoNotIgnore;
}
Upvotes: 3
Reputation: 4796
[ScriptIgnore()]
is what you want
the [NonSerialized()]
tag works only for binary serilaization, your example is one of Java script serialization
Upvotes: 3