JavaScriptSerializer - JSON serialization of enum as string

后端 未结 27 1726
耶瑟儿~
耶瑟儿~ 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 04:00

    You can also add a converter to your JsonSerializer if you don't want to use JsonConverter attribute:

    string SerializedResponse = JsonConvert.SerializeObject(
         objToSerialize, 
         new Newtonsoft.Json.Converters.StringEnumConverter()
    ); 
    

    It will work for every enum it sees during that serialization.

提交回复
热议问题