JavaScriptSerializer - JSON serialization of enum as string

后端 未结 27 1706
耶瑟儿~
耶瑟儿~ 2020-11-22 03:22

I have a class that contains an enum property, and upon serializing the object using JavaScriptSerializer, my json result contains the integer valu

27条回答
  •  不知归路
    2020-11-22 04:01

    Asp.Net Core 3 with System.Text.Json

    public void ConfigureServices(IServiceCollection services)
    {
    
        services
            .AddControllers()
            .AddJsonOptions(options => 
               options.JsonSerializerOptions.Converters.Add(new JsonStringEnumConverter())
            );
    
        //...
     }
    

提交回复
热议问题