I am currently trying to feed the cal-heatmap js with a json file in the project, with manual data entry it works fine, however I am failing to get the datatable converted to json that actually is in need, format which I am currently getting from the below code is given below
public void ConvertDataTabletoString()
{
DataTable dtjson = new DataTable();
con.Open();
SqlDataAdapter da = new SqlDataAdapter("select Date, count(id) as co from volunteer Group BY Date Order by Date", con);
da.Fill(dtjson);
con.Close();
System.Web.Script.Serialization.JavaScriptSerializer serializer = new System.Web.Script.Serialization.JavaScriptSerializer();
List<Dictionary<string, object>> rows = new List<Dictionary<string, object>>();
Dictionary<string, object> row;
foreach (DataRow dr in dtjson.Rows)
{
row = new Dictionary<string, object>();
foreach (DataColumn col in dtjson.Columns)
{
row.Add(col.ColumnName, dr[col]);
}
rows.Add(row);
}
It is generating JSON format like this
{"Date":"2/15/2016","co":8},
{"Date":"2/24/2016","co":2},
{"Date":"2/25/2016","co":1},
{"Date":"2/6/2016","co":1},
{"Date":"2/7/2016","co":4},
{"Date":"2/8/2016","co":8},
{"Date":"3/19/2016","co":17},
{"Date":"3/21/2016","co":1}
But I want the data to be in following format with no column names and multiple brackets
{
"2/15/2016": 20,
"2/24/2016": 40
}
I do not mind if you can even go ahead and do it in text file too, rather than using JSON serialization