C# 序列化时,我应该更改什么设置以获取枚举的int值而不是其字符串表示形式?

C# 序列化时,我应该更改什么设置以获取枚举的int值而不是其字符串表示形式?,c#,json,enums,json.net,refit,C#,Json,Enums,Json.net,Refit,序列化对象时,应更改什么设置以获取枚举的属性值而不是其字符串表示形式?我有以下课程 public class ProductModel { public long ProductId { get; set; } public int ContainerType { get; set; } public SolidForm SolidForm { get; set; } } (例如)现在-->MyJSON= { "ProductId" : 22222, "Cont

序列化对象时,应更改什么设置以获取枚举的属性值而不是其字符串表示形式?我有以下课程

public class ProductModel
{
    public long ProductId { get; set; }

    public int ContainerType { get; set; }

    public SolidForm SolidForm { get; set; }
}
(例如)现在-->MyJSON=

{ "ProductId" : 22222,
  "ContainerType" : 1111,
  "SolidForm" : "Solid"
}
但是我在序列化之后需要这个。(不作为字符串枚举)

我希望对象中的所有枚举都转换为int

这是我的Json序列化设置

JsonSerializerSettings = new JsonSerializerSettings
    {
        DateFormatHandling = DateFormatHandling.MicrosoftDateFormat,
        Error = delegate (object sender, ErrorEventArgs args)
        {
            args.ErrorContext.Handled = true;
        }
    }

Json中的默认值是将枚举序列化为int。假设您指的是Newtonsoft.Json


您的枚举是否用属性
[JsonConverter(typeof(StringEnumConverter))]
修饰?

Newtonsoft.Json中的默认值是将枚举序列化为int。假设您指的是Newtonsoft.Json

枚举是否用属性
[JsonConverter(typeof(StringEnumConverter))]
修饰

JsonSerializerSettings = new JsonSerializerSettings
    {
        DateFormatHandling = DateFormatHandling.MicrosoftDateFormat,
        Error = delegate (object sender, ErrorEventArgs args)
        {
            args.ErrorContext.Handled = true;
        }
    }