-1

I get the 'objType' is a variable but is used like a type compiler error when I try the following code:

Type objType = Type.GetType(objFullyQualifiedName);
object jsonObj= JsonConvert.DeserializeObject<objType> (jsonString);

How can I pass the type I obtain from the fully qualified class name to the DeserializeObject method?

John L.
  • 1,825
  • 5
  • 18
  • 45

1 Answers1

0

There is a non-generic version of DeserializeObject() that takes an instance of Type as an argument. The generic versions ultimately call this non-generic method, so the result should be the same.

Reference

Note that if such a method were not available, you could still call the generic version using reflection (compiling a dynamic method to improve performance, if needed).

Tim M.
  • 53,671
  • 14
  • 120
  • 163
  • Thanks for pointing out that non-generic method, I will use that. Could you also provide an example of how I would be able to call the generic version if possible? – John L. May 17 '17 at 01:16
  • Check out http://stackoverflow.com/questions/232535/how-do-i-use-reflection-to-call-a-generic-method – Tim M. May 17 '17 at 01:20