I have a code that will deserialized a json string and convert it to a DataSet
using Newtonsoft.Json.JsonConvert
.
I am using below SQL in API side SELECT SessionID, UserID, LogonDate, LogoffDate FROM SessionTable
. Then the result will stored on a DataTable
. There are other processing that do get data from SQL Database. Then i am adding those to a DataSet.
In API side, I am serializing the DataSet
using below:
json = JsonConvert.SerializeObject(ds);
Then in client side, i am desrializing it like below:
dataSet = JsonConvert.DeserializeObject<DataSet>(result);
The problem is when the query returns like below . The SessionID = 1
LogOffDate
is null
, it causes an error String was not recognized as a valid DateTime.
. The LogOffDate datatype becomes string. But when the first LogOffDate is not null, there are no errors.
Can some help me or suggest any way so the LogOffDate or any datetime column will always use datetime even if the first row value is null?