Same question as Deserializing stringified (quote enclosed) nested objects with Jackson but for C# and Newtonsoft Json.Net. The question is how to deserialize a nested string representation of JSON using Json.Net. Example response from REST endpoint:
{
"Id": "abcd1234",
"Foo": "{\"field1\": "abc", \"field2\": \"def\"}"
}
C# Model:
public class Model {
public Guid Id { get; set; }
public Dictionary<string, string> Foo { get; set; }
}
Just calling JsonConvert.DeserializeObject<Model>(returnedJson)
will error out because Foo in its returned form is stringified JSON, aka just a string. This is the case for other fields in our JSON response as well that have different Dictionary types associated in their models (e.g. Dictionary<string, int> and Dictionary<string, DateTime>).
What's the simplest way to handle this? Is a custom JsonConverter necessary or is there some built-in way to handle it?