Serialize Dictionary to JSON with DataContractJsonSerializer

后端 未结 3 992
余生分开走
余生分开走 2021-01-04 03:18

I have an object tree that I\'m serializing to JSON with DataContractJsonSerializer. Dictionary gets serialized but I don\'t li

3条回答
  •  一向
    一向 (楼主)
    2021-01-04 03:34

    Seems, there is no way to customize DataContractJsonSerializer.

    If you still want to achieve what you want, consider using Json.Net. It's faster and more flexible than DataContractJsonSerializer. Look at JsonConverter conception of Json.Net. It gives you the possibility to customize serialization/deserialization process.

    Moreover default implementation of dictionary serialization is exact as you want http://james.newtonking.com/projects/json/help/SerializingCollections.html.

提交回复
热议问题