jeudi 29 septembre 2016

Deserialization of Json using reflection in C#

I want to use the following Method with reflection using Newtonsoft.Json:

MyType object = JsonConvert.DeserializeObject<MyType>(jsonString);

this is my approach that doesn't work (ambiguous match exception):

        Type type = Type.GetType("MyType",false);
        Type JSONCovert = typeof(JsonConvert);
        MethodInfo deserializer = JSONCovert.GetMethod("DeserializeObject", new Type[] { typeof(String) });
        deserializer = deserializer.MakeGenericMethod(type);
        var o = deserializer.Invoke(null, new object[] { JsonString });





Aucun commentaire:

Enregistrer un commentaire