C#C
C#2y ago
20 replies
UnemployedNinja

Custom Newtonsoft JSON deserialization

I have a dictionary where:
- The key will always be a string
- The value will be either:
- string
- an object of MyClass

Normally, you would do something like:
string jsonData = ""; // Some data...
Dictionary<string, object> data = JsonConvert.DeserializeObject<Dictionary<string, object>>(jsonData);
However, this wont deserialize the non-string value into an instance of MyClass like it normally would.

How can tell the deserializer how to deserialize a string vs an object?
Was this page helpful?