默认会序列化为数字,比如下面的枚举类型
public enum Membership
{
None = 0,
Vip = 1,
Plus = 2
}
添加 JsonStringEnumConverter 可以解决
services.AddControllers()
.AddJsonOptions(o =>
{
o.JsonSerializerOptions.Converters.Add(new JsonStringEnumConverter());
});