Json.net deserializing list gives duplicate items

前端 未结 4 1235
眼角桃花
眼角桃花 2021-02-18 15:56

I have just started using Newtonsoft.Json (Json.net). In my first simple test, I ran into a problem when deserializing generic lists. In my code sample below I serialize an obje

4条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-02-18 16:46

    How to apply ObjectCreationHandling.Replace to selected properties when deserializing JSON?

    Turns out (I'm in 2019), you can set the list items in your constructor as you were doing in your question. I added the ObjectCreationHandling.Replace attribute above my declaration of the list, then serialising should replace anything stored in the list with the JSON.

提交回复
热议问题