REST API wrapper design: returning dynamic json as JSON.NET JObject / JArray

前端 未结 1 1180
粉色の甜心
粉色の甜心 2021-01-19 01:08

I am writing a C# wrapper for a RESTful JSON API, and using Json.NET to deserialize the incoming json to strongly typed object. but a few properties in the incoming json are

相关标签:
1条回答
  • 2021-01-19 01:20

    You should use ExpandoObjectConverter instead.

    You need to type your IDictionary<string, object> as just dynamic and decorate the whole property with [JsonConverter(typeof(ExpandoObjectConverter))].

    One interesting detail is ExpandoObject also implements IDictionary<string, object>, but when you type it with dynamic, you can access associated properties like regular ones! ;)

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