title: using MySQL to create JSON with C# and JSON.Net
body: <p>I am having quite a lot of trouble trying to find a tutorial that will tech me how to use MySqlReader (with MySQL) to insert or receive data through a class object. The construtor is shown as follow. </p>
  
  <p>Where I have used <a href="http://json2csharp.com/" rel="nofollow">http://json2csharp.com/</a> to create these class I know how to serialize/deserialize a class object into JSON. my problem really lies in getting the data from a lot of different table in and out of the database connector via MySqlDataReader into a class object.</p>
  
  <p>I don't know if this matter but I am using .Net 2.0 with C# 3.0 (visual studio 2010). Thank you in advance for any comment or reply.</p>
  
  <pre><code>public class Boardingzone
  {
      public string zone { get; set; }
      public string time { get; set; }
  }
  
  public class Serial
  {
      public string rsn { get; set; }
      public List&lt;Boardingzone&gt; boardingzone { get; set; }
  }
  
  public class RootObject
  {
      public string name { get; set; }
      public List&lt;Serial&gt; serial { get; set; }
  }
  </code></pre>
  
  <p>This is what i have tried so far</p>
  
  <pre><code>        string sql = "SELECT Route.RName, RouteSerial.RSN, Stop.StopName, TimeTable.BoardTime FROM TimeTable INNER JOIN Stop ON TimeTable.StopID = Stop.StopID INNER JOIN RouteSerial ON TimeTable.RSN = RouteSerial.RSN INNER JOIN Route ON RouteSerial.RID = Route.RID";
          MySqlCommand cmd = new MySqlCommand(sql, conn);
          MySqlDataReader rdr = cmd.ExecuteReader();
          ArrayList name = new ArrayList();
          ArrayList rsn = new ArrayList();
          ArrayList zone = new ArrayList();
          ArrayList time = new ArrayList();
  
          while (rdr.Read()){
              string val = "";
              val = rdr.GetValue(0).ToString();
              name.Add(val);
              val = rdr.GetValue(1).ToString();
              rsn.Add(val);
              val = rdr.GetValue(2).ToString();
              zone.Add(val);
              val = rdr.GetValue(3).ToString();
              time.Add(val);
          }
          rdr.Close();
      conn.Close();
  </code></pre>