I have a Dictionary
and I need to convert it into a List
where Data
has the properties lab
This is a old post, but post only to help other persons ;)
Example to convert any object type:
public List Select(string filterParam)
{
DataTable dataTable = new DataTable()
//{... implement filter to fill dataTable }
List> rows = new List>();
Dictionary row;
foreach (DataRow dr in dataTable.Rows)
{
row = new Dictionary();
foreach (DataColumn col in dataTable.Columns)
{
row.Add(col.ColumnName, dr[col]);
}
rows.Add(row);
}
string json = new JavaScriptSerializer().Serialize(rows);
using (MemoryStream stream = new MemoryStream(Encoding.UTF8.GetBytes(json)))
{
DataContractJsonSerializer deserializer = new DataContractJsonSerializer(typeof(T[]));
var tick = (T[])deserializer.ReadObject(stream);
return tick.ToList();
}
}