我有一个像这样的枚举
public enum MyEnum: smallint
{
[Description("Prop1")] Prop1= 0,
[Description("Prop2")] Prop2= 1,
[Description("Prop3")] Prop3= 2,
[Description("Prop4")] Prop4= 3
}
我在课堂上使用它的位置:
public IEnumerable<MyEnum> myEnum {get;set}
我在我的Json正文中尝试过将值传递给myEnum
:
{
"myEnum":[
{
"MyEnum":"1"
},
{
"MyEnum":"2"
}
]
}
我知道这是错误的,因为它显示了一个错误:“ Cannot deserialize the current JSON object (e.g. {\"name\":\"value\"}) into type 'System.Nullable 1 . . . .
”
我想知道如何通过JSON将值传递给myEnum
。 TIA
如果您使用C#,也许这就是您所需要的。如果是这样,我们可以将标记设置为重复。Json serialization of enum as string