开发者

JSON.NET Deserialize string abbreviation into Enum

开发者 https://www.devze.com 2023-04-09 12:33 出处:网络
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:

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,

}
0

精彩评论

暂无评论...
验证码 换一张
取 消