How to (de)serialise JSON data in Silverlight using a different name to member variable
-
05-07-2019 - |
Question
I have the following members defined in a class that I'm trying to deserialise:
[DataMemberAttribute(Name = "cust_title")]
public String Title { get; set; }
[DataMemberAttribute(Name = "cust_description")]
public String Description { get; set; }
For some reason, the deserialisation fails (it seems to ignore the DataMemberAttribute).
Does anyone know how to get this working?
Solution
I've just found the answer out by a bit of trial and error. In order to use the [DataMemberAttribute]
you must also put [DataContractAttribute]
above your class definition:
[DataContractAttribute]
public class MyClass
{
[DataMemberAttribute(Name="test_test")]
public String Test { get; set; }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow