使用JSON反序列化的枚举始终为0

时间:2015-06-12 23:56:25

标签: c# json enums

我有一个Parameter类,它有一个属性TypeOfParameter,它是一个枚举:

def expand_input(input):
    temp = input.split("*")
    return [temp[0]+x for x in temp[1:]] if len(temp)>1 else input

当我序列化它时(使用Biggy JSON数据存储),它正确地将数字参数序列化为2:

public ParameterType TypeOfParameter { get;  set; }
public enum ParameterType {Completion, Boolean, Numeric, Range, Text, Undefined };

但是当我检索/反序列化Parameter时,它总是返回ParameterType的0(完成)。参数有两个构造函数。一个允许我传递所有属性的值,另一个是无参数构造函数。在反序列化数据并正确分配所有其他属性时,将调用无参数构造函数。仅错误地分配了枚举。

知道我可能做错了吗?

编辑: 这是Parameter类和JSON。请注意,JSON适用于我的Sample类,它具有List和SampleTest具有List。

"TypeOfParameter":2

JSON:

public class Parameter
    {
        public string ParameterName { get;  set; }
        public string Unit { get;  set; }
        public ParameterType TypeOfParameter { get;  set; }
        public double? LowerLimit { get;  set; }
        public double? UpperLimit { get;  set; }
        public bool Selected { get; set; }
        public string Formula { get;  set; }

        public Parameter(string name, string unit, ParameterType typeOfParameter = ParameterType.Numeric,
            double? lowerLimit = null, double? upperLimit = null)
        {
            this.ParameterName = name;
            this.Unit = unit;
            this.TypeOfParameter = typeOfParameter;
            this.LowerLimit = lowerLimit;
            this.UpperLimit = upperLimit;

            this.Selected = true;
        }

        public Parameter()
        {       }

        public void ToggleSelection()
        {
            this.Selected = !this.Selected;
        }

        public enum ParameterType {Completion, Boolean, Numeric, Range, Text, Undefined };
    }

0 个答案:

没有答案