String
{
"Answer": [{
"Patientid": "XX",
"Question": "158",
"Answercontent": "3"
}, {
"Patientid": "AA",
"Question": "159",
"Answercontent": "2"
}]
}
Public DataTable Jsontdb (string Strjson)
{
DataTable datatable = new DataTable (); Instantiation of
DataTable result;
Try
{
JavaScriptSerializer JavaScriptSerializer = new JavaScriptSerializer (); Reference System.Web.Extensions
Javascriptserializer.maxjsonlength = Int32.MaxValue; Get the maximum value
ArrayList ArrayList = javascriptserializer.deserialize<arraylist> (Strjson);
if (Arraylist.count > 0)
{
foreach (dictionary<string, object> Dictionary in ArrayList)
{
if (dictionary. keys.count<string> () = = 0)
{
result = dataTable;
return result;
}
if (DataTable.Columns.Count = = 0)
{
foreach (String current in dictionary. Keys)
{
DATATABLE.COLUMNS.ADD (current, dictionary[current]. GetType ());
}
}
DataRow datarow = Datatable.newrow ();
foreach (String current in dictionary. Keys)
{
Datarow[current] = dictionary[current];
}
DATATABLE.ROWS.ADD (DataRow); Loop to add rows to the DataTable
}
}
}
Catch
{
}
return dataTable;
return result;
}
Convert a JSON string to a DataTable