-
-
Save poychang/35489bc7cfd46f4cd02258d9938f0591 to your computer and use it in GitHub Desktop.
[設定 ASP.NET Core 可以序列化 Enum]- 修改 MVC 的 Json 序列化設定,使之可以將 Enum 序列化成文字併忽略 null 值 #dotnet #csharp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Startup | |
{ | |
public IServiceProvider ConfigureServices(IServiceCollection services) | |
{ | |
services.AddMvc().AddJsonOptions(options => | |
{ | |
options.SerializerSettings.Converters.Add(new Newtonsoft.Json.Converters.StringEnumConverter()); | |
options.SerializerSettings.NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore; | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment