JavaScriptserializer enumerated string serialization method Detailed explanation
Attribute -based converter
type. This will indicate that the serialization program converts the enumeration value to a string: [JsonConverter]
StringEnumConverter
<code class="language-csharp">using Newtonsoft.Json; using Newtonsoft.Json.Converters; [JsonConverter(typeof(StringEnumConverter))] public Gender Gender { get; set; }</code>
StringEnumConverter
JsonSerializer
Global configuration
<code class="language-csharp">serializer.Converters.Add(new Newtonsoft.Json.Converters.StringEnumConverter());</code>
enumeration: JsonConverter
jsonconveter:
<code class="language-csharp"> [JsonConverter(typeof(StringEnumConverter))] public enum Gender { Male, Female }</code>
Other options Lialingcase:
Use the<code class="language-csharp"> JsonConvert.SerializeObject(MyObject, new Newtonsoft.Json.Converters.StringEnumConverter());</code>
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!