title: How can I convert from an IList<x> to a JSON string and back?
body: <p>I have the following class:</p>
  
  <pre><code>public class TestQuestionHeader
  {
      public int Id { get; set; }
      public int QId { get; set; }
  }
  </code></pre>
  
  <p>and JSON methods:</p>
  
  <pre><code>public static string ToJSONString(this object obj)
  {
      using (var stream = new MemoryStream())
      {
          var ser = new DataContractJsonSerializer(obj.GetType());
  
          ser.WriteObject(stream, obj);
  
          return Encoding.UTF8.GetString(stream.ToArray());
      }
  }
  
  public static T FromJSONString&lt;T&gt;(this string obj)
  {
      using (var stream = new MemoryStream(Encoding.UTF8.GetBytes(obj)))
      {
          DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(T));
          T ret = (T)ser.ReadObject(stream);
          return ret;
      }
  }
  </code></pre>
  
  <p>I am using these as follows:</p>
  
  <pre><code>IList&lt;TestQuestionHeaders&gt; testQuestionHeaders = xxx;
  string test.Questions = JSON.ToJSONString(testQuestionHeaders);
  var a = JSON.FromJSONString&lt;TestQuestionHeader&gt;(test.Questions);
  </code></pre>
  
  <p>Can someone help me to explain why the variable <code>a</code> contains  <code>TestQuestionHeader</code>
   instead of <code>IList&lt;TestQuestionHeader&gt;</code> </p>