jeudi 21 mai 2015

typify a list dynamically json.net, deserialization with reflection

I have a little problem. I should deserialize a json through libraries json.net in c #. I can not understand how you can switch typing the list in bold, of course, all using the reflection, because I'm doing a generic method.

Someone can give me an enlightment? or the solution :)

string serviceString = "eStartService." + tabella;

Type **type** = serviceString.GetType();
Type listType = typeof(List<>).MakeGenericType(new[] { type });
IList list = (IList)Activator.CreateInstance(listType);

list = JsonConvert.DeserializeObject<List<**type**>>(json);

I can not declare an object instead of type, because all I have to be dynamic and I do not know any object using reflection I get the json.

thanks





Aucun commentaire:

Enregistrer un commentaire