Deserializing nested JSON structure to a flattened class with Json.NET using annotations

前端 未结 3 1423
面向向阳花
面向向阳花 2020-12-17 08:52

Is it possible to use JsonProperty annotation to map a nested Json property to a non-nested .NET member? Say you\'ve got some Json like this:

{
     \"id\":9         


        
3条回答
  •  一向
    一向 (楼主)
    2020-12-17 09:21

    From personal experience, I struggled before trying to re-use my entities for communication (JSON, XML ... etc.) but after paying closer attention to existing patterns, I found out that having "data transfer objects" in addition to internal / storage entities that you already have will liberate my communication models and the only cost I paid was to accept doing manual, yet straight-forward, effort of manually-coded conversion between the two.

    If you'd rather stick to what you have and performance is no big deal, then .NET reflection is your friend.

提交回复
热议问题