Saturday, 31 August 2013

Deserialize json character as enumeration

Deserialize json character as enumeration

I have an enumeration, where I'm storing it's values as characters, like
this:
public enum CardType
{
Artist = 'A',
Contemporary = 'C',
Historical = 'H',
Musician = 'M',
Sports = 'S',
Writer = 'W'
}
When the JSON is written, it looks like this:
[{"CardType","A"},{"CardType", "C"}]
Now when I attempt to deserialize, it's trying to read that value back
into the Enumeration, but something is wrong, because after
deserialization, the CardType value is always zero (0) as if the
deserialization failed.
Is there an extra step I need to get this to deserialize an enumeration
correctly?
Please let me know if I haven't provided enough information here, thanks!

No comments:

Post a Comment