1

When calling json.net Parse method to deserialize json array string: Either:

JArray.Parse(jsonArrayString)

Or

JObject.Parse(jsonArrayString with root node)

It always remove the trailing zero in timestamp milliseconds, e.g.

data: "TimeStamp": "2019-10-01T11:36:43.840-04:00", After deserilization: "TimeStamp": "2019-10-01T11:36:43.84-04:00",

Found a bug before with json.net on remove trailing zero from decimals:https://github.com/JamesNK/Newtonsoft.Json/issues/1367 And updated newtonsoft.json from 10.0.1 to latest 12.0.2, but no luck with timestamp

jsonArrayString example:

[{"HistoryId": 430,"TimeStamp": "2019-10-01T11:36:43.840-04:00"}]

Then invoke with above value:

JArray.Parse(jsonArrayString)
TheGeneral
  • 79,002
  • 9
  • 103
  • 141
OscarZ
  • 51
  • 4
  • `DateTime` has no precision data inside, so you will need to disable `DateTime` recognition. To do that see [Json.NET Disable the deserialization on DateTime](https://stackoverflow.com/a/11856835/3744182). – dbc Oct 01 '19 at 23:59
  • Great. The suggested solution works for JObject. Wonder is there a solution for JArray.Parse? – OscarZ Oct 02 '19 at 03:17
  • Use `JsonConvert.DeserializeObject(jsonArrayString, settings)` – dbc Oct 02 '19 at 03:54
  • Or `var reader = new JsonTextReader(new StringReader(jsonArrayString)) { DateParseHandling = DateParseHandling.None }; var array = JArray.Load(reader);` – dbc Oct 03 '19 at 15:54

0 Answers0