I know that I can use JsonConvert.DeserializeObject
, however, I need to peek into the object\'s _type
(which may not be the first
JSON.NET has no direct ability to support both requisites:
The first requisites is fulfilled by JsonSubTypes The second one by specifying thh right MetadataPropertyHandling
First parse the JSON into a JObject. Then lookup the _type
attribute using LINQ to JSON. Then switch depending on the value and cast using ToObject<T>
:
var o = JObject.Parse(text);
var jsonType = (String)o["_type"];
switch(jsonType) {
case "something": return o.ToObject<Type>();
...
}