JavaScriptSerializer - JSON serialization of enum as string

后端 未结 27 1751
耶瑟儿~
耶瑟儿~ 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 03:59

    And for VB.net I found the following works:

    Dim sec = New Newtonsoft.Json.Converters.StringEnumConverter()
    sec.NamingStrategy() = New Serialization.CamelCaseNamingStrategy
    
    Dim JSON_s As New JsonSerializer
    JSON_s.Converters.Add(sec)
    
    Dim jsonObject As JObject
    jsonObject = JObject.FromObject(SomeObject, JSON_s)
    Dim text = jsonObject.ToString
    
    IO.File.WriteAllText(filePath, text)
    

提交回复
热议问题