My class has a property 'PropertyA', I want this to appear as 'PropertyB' in a JSON object when it's serialized. Is there any sort of attribute I can use?
For Json.NET and DataContractJsonSerializer use DataMemberAttribute:
Json.NET
DataContractJsonSerializer
DataMemberAttribute
[DataMember(Name="PropertyB")] T PropertyA { ... }
Make sure that your class is decorated with the [DataContract] attribute as well.
[DataContract]
If you're using JavaScriptSerializer, you need to create derived implementation, as described here: JavaScriptSerializer.Deserialize - how to change field names
1.4m articles
1.4m replys
5 comments
57.0k users