JavaScriptSerializer - JSON serialization of enum as string

后端 未结 27 2124
耶瑟儿~
耶瑟儿~ 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:09

    This is an old question but I thought I'd contribute just in case. In my projects I use separate models for any Json requests. A model would typically have same name as domain object with "Json" prefix. Models are mapped using AutoMapper. By having the json model declare a string property that is an enum on domain class, AutoMapper will resolve to it's string presentation.

    In case you are wondering, I need separate models for Json serialized classes because inbuilt serializer comes up with circular references otherwise.

    Hope this helps someone.

提交回复
热议问题