title: Save and Load C# list of different types from JSON
body: <p>I am using JSON to serialize and deserialize a list in c#. Everything works if the list is made up of objects of a single type. My goal is to find a way to store a list (or queue or something similar) of objects of different types that I can load and iterate over later and perform operations on. I could break my serialization up into multiple lists, but it is important to iterate over the objects in the order that they were added, so having them all be a part of the same data structure is ideal. </p>
  
  <p>I tried having a DataModelBase class that they all inherit from and having a list of type DataModelBase, which works at runtime and when saving, but the load / deserialize function I was not able to get to work. I also tried using an interface as well and passing custom parameters to my deserialize call, but this caused my Unity application to crash. Is there a better way to go about what I am trying to achieve?</p>
  
  <p>This is my load function:</p>
  
  <pre><code>public static T LoadData&lt;T&gt;(string path)
      {
          using (var reader = new StreamReader(path))
          {
              var fileContents = reader.ReadToEnd();
              reader.Close();
              reader.Dispose();
              return JsonConvert.DeserializeObject&lt;T&gt;(fileContents);
          }
      }
  </code></pre>
  
  <p>The error that I am commonly getting when trying to convert an entry in my list to my class type is: RuntimeBinderException: Cannot implicitly convert type <code>Newtonsoft.Json.Linq.JObject' to</code>Type I am trying to convert to'</p>