JSON.NET Deserialize string abbreviation into Enum
I am just getting into JSON and all that and I ran into a snag. I am trying to parse a string abbreviation. I want to parse the string abbreviation into an Enum. Lets say my strings are:
'Apl', 'Orng', 'Bna'
Which for this example mean apple, orange, banana. Is there a way with JSON.NET to parse the abbreviated strings into an开发者_高级运维 enum?
*Id prefer it if my enum can have the full name (Apple, Orange, Banana)
I think you're supposed to do this:
[DataContract]
public enum Fruit
{
[EnumMember(Value = "Apl")]
Apple,
[EnumMember(Value = "Orng")]
Orange,
[EnumMember(Value = "Bna")]
Banana,
}
精彩评论