I am trying to parse JSON data to a DataTable
in C#. But while parsing I am seeing a Newtonsoft.Json.JsonSerializationException
.
Error converting value "" to type 'System.DateTime'. Path '[1]['Created Date']', line 8, position 20.
Here is the code which I used to parse the data:
DataTable dtData = JArray.Parse(jsonString).ToObject<DataTable>();
Sample JSON data:
[
{
"rno": 1,
"Name": "XYZ",
"Created Date": "2014-04-30T14:39:12.2397769Z"
},
{
"rno": 2,
"Name": "ABC",
"Created Date": ""
}
]
Can someone tell me how to manage this type of scenario. I just want to prevent a data type change while adding data into the data table. Instead of DateTime
, the column data type should be set as string.