Vote count:
0
I am using Json.Net to deserialize json results into ExpandoObjects using code like the following:
var converter = new ExpandoObjectConverter();
dynamic d = JsonConvert.DeserializeObject<ExpandoObject>(json, converter);
This works great for everything except responses that have only a list at the root of the json schema such as this:
string json = @"[{""title"": ""the title""}]";
In the bowels of JsonConvert is this method:
public static T DeserializeObject<T>(string value, params JsonConverter[] converters)
{
return (T)DeserializeObject(value, typeof(T), converters);
}
The return value DeserializeObject is a properly constructed List<object> with on ExpandoObject in it but the code fails trying to cast that list to an ExpandoObject itself (the value of T).
I've got a failing unit test and could fix this but am not sure how to stuff a List directly into an ExpandoObject.
Is this possible? DynamicObject has TryGetIndex so I assume an ExpandoObject can have an indexer. Would it be necessary to carefully construct a list-like instance of expando by dynamically supplying the implementation of an indexing method or otherwise create a non-expando DynamicObject to hold the list and invoke the correctly methods from dynamic method calls?
Aucun commentaire:
Enregistrer un commentaire