I am using the DataContractJsonSerializer class to serialise my objects to JSON.
Is there an attribute I can use on fields in my custom objects (C#) that will turn off serialisation for that one particular field?
I am using the DataContractJsonSerializer class to serialise my objects to JSON.
Is there an attribute I can use on fields in my custom objects (C#) that will turn off serialisation for that one particular field?
If you use the DataContractAttribute to decorate your class, you will then be required to use the DataMemberAttribute to mark the fields/properties that you want to have serialized. I don't think that there is any attribute that can turn off serialization of a public property/field on a class without the DataContractAttribute. MSDN has a tutorial on how to serialize data as JSON.
Actually, there is a way: IgnoreDataMemberAttribute
See http://msdn.microsoft.com/en-us/library/system.runtime.serialization.ignoredatamemberattribute.aspx and http://msdn.microsoft.com/en-us/library/cc656732.aspx for full documentation.