title: Creating Json file with C# of mysql data
body: <p>I tried to create a json file of mysql database and it works with the code down below but i dont know how to give them a "header" that i need to fetch data from this json with volley in android studio i need:
   **this is only an example to let you know which section i need , i dont need "colors" **</p>
  
  <pre><code> {
       **"colors"**: [//   i need this section here but with my code i couldnt 
     //get this.
      {
        "color": "black",
        "category": "hue",
        "type": "primary",
        "code": {
         "rgba": [255,255,255,1],
         "hex": "#000"
        }
   } 
  </code></pre>
  
  <p>VOLLEY in android studio does this to get data :</p>
  
  <blockquote>
    <p>JSONArray jsonArray=response.getJSONArray("<strong>colors</strong>");</p>
  </blockquote>
  
  <p>Heres my code in C# for creating a Json file at localhost</p>
  
  <pre><code>namespace MySqlServerDemo
  {
      public partial class WebForm1 : System.Web.UI.Page
      {
  
  
          protected void Page_Load(object sender, EventArgs e)
          {
  
              Response.Write( ListJson() );
  
          }
  
          //    [WebMethod]
          public static string ListJson()
          {
              DataSet ds = new DataSet();
  
              MySqlConnection con = new MySqlConnection("server=localhost;user id=root;database=studentdetails;password=MYPASSWORD");
              con.Open();
              MySqlCommand cmd = new MySqlCommand("select * from STUDENTS", con);
              MySqlDataAdapter da = new MySqlDataAdapter(cmd);
  
  
              da.Fill(ds);
  
                  List&lt;students&gt; studentDetails = new List&lt;students&gt;();
                  studentDetails = ConvertDataTable&lt;students&gt;(ds.Tables[0]);
  
              JavaScriptSerializer js = new JavaScriptSerializer();
                  return js.Serialize(studentDetails);
  
              }
  
          public class students
          {
              public string firstname { get; set; }
              public string surname { get; set; }
  
          }
  
  
          private static List&lt;T&gt; ConvertDataTable&lt;T&gt;(DataTable dt)
          {
              List&lt;T&gt; data = new List&lt;T&gt;();
              foreach (DataRow row in dt.Rows)
              {
                  T item = GetItem&lt;T&gt;(row);
                  data.Add(item);
              }
              return data;
          }
          private static T GetItem&lt;T&gt;(DataRow dr)
          {
              Type temp = typeof(T);
              T obj = Activator.CreateInstance&lt;T&gt;();
  
              foreach (DataColumn column in dr.Table.Columns)
              {
                  foreach (PropertyInfo pro in temp.GetProperties())
                  {
                      if (pro.Name == column.ColumnName)
                          pro.SetValue(obj, dr[column.ColumnName], null);
                      else
                          continue;
                  }
              }
              return obj;
          }
      }
  }
  </code></pre>