Difference between DataMember and JsonProperty in webapi2

前端 未结 1 1827
[愿得一人]
[愿得一人] 2021-02-20 07:17

What is the difference between DataMember and JsonProperty when using it in webapi2? Any performance differences? What is preferred to use?

Thanks! Andreas

1条回答
  •  野趣味
    野趣味 (楼主)
    2021-02-20 07:39

    In WebAPI, the default JSON formatter is Json.NET.

    Json.NET is the one who reads the DataMember and JsonProperty attributes. JsonProperty is from Json.NET and its purpose is to control how the field or property is serialized. While DataMember, which is from Microsoft, is read by Json.NET for convenience.

    JsonProperty provides more configuration options than DataMember.

    0 讨论(0)
提交回复
热议问题