R
RMittelman
Guest
So I have a 1-row DataTable which I serialized using Json.Net. Now I want to add functionality to deserialize it. The Json looks like this (abbreviated for simplicity):
{"TableName":"tblNAMaster","Columns":[{"AllowDBNull":false,"AutoIncrement":true,"AutoIncrementSeed":0,
"AutoIncrementStep":1,"Caption":"NAID","ColumnName":"NAID","DataType":"Int32","DateTimeMode":"UnspecifiedLocal",
"DefaultValue":null,"MaxLength":-1,"Ordinal":0,"ReadOnly":true,"Unique":false},{"AllowDBNull":true,
"AutoIncrement":false,"AutoIncrementSeed":0,"AutoIncrementStep":1,"Caption":"NAChgDate","ColumnName":"NAChgDate",
"DataType":"DateTime","DateTimeMode":"UnspecifiedLocal","DefaultValue":null,"MaxLength":-1,"Ordinal":1,
"ReadOnly":false,"Unique":false},
...
],"Rows":[[1,"2019-06-30T00:00:00","","","Jones","John","Jones,John","John Jones","1234 Main St.",
"Thousand Oaks","CA",91360,"1234 Main St., Thousand Oaks, CA 91360","8057500731",null,"myEmail@myDomain.com",
"F","Regular",null,"2020-07-01T00:00:00",null,null]],"PrimaryKey":[]}
This is how it was serialized:
var dtJson = JsonConvert.SerializeObject(dt, new Serialization.DataTableConverter());
This is how I tried to deserialize:
var json = Request.Body.ToString();
using (DataTable dt = JsonConvert.DeserializeObject<DataTable>(json, new Serialization.DataTableConverter()))
{
// other code here
}
I get this error in Postman:
{"statusCode":500,"message":"Something went horribly, horribly wrong while servicing your request.",
"details":"<pre>Nancy.RequestExecutionException: Oh noes!\r\n ---< Newtonsoft.Json.JsonReaderException:
Error parsing NaN value. Path '', line 1, position 2.\r\n
at Newtonsoft.Json.JsonTextReader.ParseNumberNaN(ReadType readType, Boolean matched)\r\n
at Newtonsoft.Json.JsonTextReader.ParseValue()\r\n
.... etc etc
I also tried this:
var json = Request.Body.ToString();
var settings = new JsonSerializerSettings
{
NullValueHandling = NullValueHandling.Ignore,
MissingMemberHandling = MissingMemberHandling.Ignore
};
using (DataTable dt = JsonConvert.DeserializeObject<DataTable>(json, settings))
{
// other code here...
}
But I still get the same error. Can't figure out why this json text, which was serialized by Json.Net, can't simply be deserialized in one command.
Any ideas? Thanks...
Ron Mittelman
Continue reading...
{"TableName":"tblNAMaster","Columns":[{"AllowDBNull":false,"AutoIncrement":true,"AutoIncrementSeed":0,
"AutoIncrementStep":1,"Caption":"NAID","ColumnName":"NAID","DataType":"Int32","DateTimeMode":"UnspecifiedLocal",
"DefaultValue":null,"MaxLength":-1,"Ordinal":0,"ReadOnly":true,"Unique":false},{"AllowDBNull":true,
"AutoIncrement":false,"AutoIncrementSeed":0,"AutoIncrementStep":1,"Caption":"NAChgDate","ColumnName":"NAChgDate",
"DataType":"DateTime","DateTimeMode":"UnspecifiedLocal","DefaultValue":null,"MaxLength":-1,"Ordinal":1,
"ReadOnly":false,"Unique":false},
...
],"Rows":[[1,"2019-06-30T00:00:00","","","Jones","John","Jones,John","John Jones","1234 Main St.",
"Thousand Oaks","CA",91360,"1234 Main St., Thousand Oaks, CA 91360","8057500731",null,"myEmail@myDomain.com",
"F","Regular",null,"2020-07-01T00:00:00",null,null]],"PrimaryKey":[]}
This is how it was serialized:
var dtJson = JsonConvert.SerializeObject(dt, new Serialization.DataTableConverter());
This is how I tried to deserialize:
var json = Request.Body.ToString();
using (DataTable dt = JsonConvert.DeserializeObject<DataTable>(json, new Serialization.DataTableConverter()))
{
// other code here
}
I get this error in Postman:
{"statusCode":500,"message":"Something went horribly, horribly wrong while servicing your request.",
"details":"<pre>Nancy.RequestExecutionException: Oh noes!\r\n ---< Newtonsoft.Json.JsonReaderException:
Error parsing NaN value. Path '', line 1, position 2.\r\n
at Newtonsoft.Json.JsonTextReader.ParseNumberNaN(ReadType readType, Boolean matched)\r\n
at Newtonsoft.Json.JsonTextReader.ParseValue()\r\n
.... etc etc
I also tried this:
var json = Request.Body.ToString();
var settings = new JsonSerializerSettings
{
NullValueHandling = NullValueHandling.Ignore,
MissingMemberHandling = MissingMemberHandling.Ignore
};
using (DataTable dt = JsonConvert.DeserializeObject<DataTable>(json, settings))
{
// other code here...
}
But I still get the same error. Can't figure out why this json text, which was serialized by Json.Net, can't simply be deserialized in one command.
Any ideas? Thanks...
Ron Mittelman
Continue reading...