Attribute -based converter
type. This will indicate that the serialization program converts the enumeration value to a string: [JsonConverter]
StringEnumConverter
using Newtonsoft.Json; using Newtonsoft.Json.Converters; [JsonConverter(typeof(StringEnumConverter))] public Gender Gender { get; set; }
StringEnumConverter
JsonSerializer
Global configuration <全>
serializer.Converters.Add(new Newtonsoft.Json.Converters.StringEnumConverter());
<枚> enumeration: JsonConverter
jsonconveter:
[JsonConverter(typeof(StringEnumConverter))] public enum Gender { Male, Female }
Other options <<> <小> Lialingcase:
Use theJsonConvert.SerializeObject(MyObject, new Newtonsoft.Json.Converters.StringEnumConverter());
The above is the detailed content of How to Serialize Enums as Strings Using JavaScriptSerializer?. For more information, please follow other related articles on the PHP Chinese website!