title: Deserialize json string into a list of .NET objects
body: <p><strong>Requirement</strong></p>
  
  <p>I am trying to build a function that takes a json string as input. and outputs list of object.
  The json string is in a similar format to this:</p>
  
  <pre><code>{\"custlist\":[{\"cust_name\":\"Vincent\",\"cust_id\":\"klq:206f387:2d08m92t6\"},{\"cust_name\":\"Joyce\",\"cust_id\":\"125g:1474grx:2d03t9dld\"}]}
  </code></pre>
  
  <p><strong>My Search</strong></p>
  
  <p>There are plenty of solutions deserialize json array to list of objects, but the array starts at the beginning of the string. i.e. without the \"custlist\": part</p>
  
  <p>If we have \"custlist\": part in the json string, those solutions break.</p>
  
  <p><strong>My Code</strong></p>
  
  <p>Here is my code in C#. It is working, but I had to use regular expression to match the input string. Seems over-complicated. There must be an easier way. Anyone knows, please kindly advise</p>
  
  <pre><code>    public void Test()
      {
          string str = {\"custlist\":[{\"cust_name\":\"Vincent\",\"cust_id\":\"klq:206f387:2d08m92t6\"},{\"cust_name\":\"Joyce\",\"cust_id\":\"125g:1474grx:2d03t9dld\"}]};
  
          List&lt;Customer&gt; list = Json2List&lt;Customer&gt;(str);
          foreach (Customer c in list)
          {
              console.writeline ("name=" + c.cust_name);
              console.writeline ("id=" + c.cust_id);
          }
  
      }
  
  
      public List&lt;T&gt; Json2List&lt;T&gt;(string s)
      {
          string json_listname = Regex.Match(s, "\"" + @"(\w+?)" + "\":").Groups[0].Value;
          JObject jObject = JObject.Parse(s);
          List&lt;JToken&gt; jTokenList = jObject.GetValue(json_listname).ToList();
  
          List&lt;T&gt; LstT = new List&lt;T&gt;();
          foreach (JToken jt in jTokenList)
          {
              T obj = jt.ToObject&lt;T&gt;();
              LstT.Add(obj);
  
          }
  
          return LstT;
  
      }
  
  public class Customer
  {
      public string cust_name { get; set; }
      public string cust_id { get; set; }
  
  }
  </code></pre>