For example, there\'s an object like the next one:
public class Container
{
public object Data { get; set; }
}
And it\'s used this way:<
Try this:
Container container = new Container
{
Data = new Dictionary<string, object> { { "Text", "Hello world" } }
};
string jsonText = JsonConvert.SerializeObject(container);
var obj = JsonConvert.DeserializeObject<ExpandoObject>(jsonText, new ExpandoObjectConverter());
I found that doing this got me an ExpandoObject
from the call to DeserializeObject
. I think the issue with the code you have provided is that while you are supplying an ExpandoObjectConverter
, you are asking Json.Net
to deserialize a Container
, so I would imagine that the ExpandoObjectConverter
is not being used.
Edit:
If I decorate the Data
property with [JsonConverter(typeof(ExpandoObjectConverter))]
and use the code:
var obj = JsonConvert.DeserializeObject<Container>(jsonText);
Then the Data
property is deserialized to an ExpandoObject
, while obj
is a Container
.