I tried to convert DataTable to JSON string using JObject (NewtonSoft.dll). In my case table may have values with different data types. I want to convert those values to string while serialize the object.
DataTable tab = new DataTable();
tab.Columns.Add("ID", typeof(int));
tab.Columns.Add("Name");
tab.Rows.Add(1, "Role1");
tab.Rows.Add(2, "Role2");
string strValues = JsonConvert.SerializeObject(tab);
--output of strValues
-- [{"ID":1,"Name":"Role1"},{"ID":2,"Name":"Role2"}]
But it should be like this -
[{"ID":"1","Name":"Role1"},{"ID":"2","Name":"Role2"}]
Please give me the solution. Thanks