JObject.Parse vs DateTime
See original GitHub issueGiven the following code snippet
String js = "{ \"DateTime\": \"2017-03-07T17:26:40.352Z\" }";
var jo = JObject.Parse(js);
String ds1 = (String)jo["DateTime"];
results "ds1 = “03/07/2017 17:26:40"” which is not quite correct, because it misses fractions of second and timezone information. DateTime.Parse/TryParse will not be correct then. This is a problem in my app, because I want to use DateTime.TryParse to check for correctly formatted input data. I cannot use (DateTime)jo[“DateTime”] because it might throw an exception. (Yes, this exception could be caught, but this is what TryParse is for, isn’t it).
Actually I would have expected ds1 to be “2017-03-07T17:26:40.352Z”, but this may be another story…
Issue Analytics
- State:
- Created 7 years ago
- Comments:6
Top Results From Across the Web
How to avoid JObject.Parse parsing a DateTime, and ...
Basically he wants Json.net to not interpret it as a DateTime and instead just return the original string directly.
Read more >DateParseHandling Enumeration
DateParseHandling Enumeration ; None, 0, Date formatted strings are not parsed to a date type and are read as strings. ; DateTime, 1,...
Read more >Json.NET unexpected defaults for parsing date - Vincent Costel
Because, by default, if the parser recognizes an ISO8601 date string, it will automatically convert it to a DateTime object, therefore losing ...
Read more >DateTime.Parse Method (System)
The Parse method tries to convert the string representation of a date and time value to its DateTime equivalent. It tries to parse...
Read more >String To DateTime Conversion In C#
DateTime.Parse() · Value. It is a string representation of date and time. · Provider. It is an object which provides culture-specific info.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Found better one.
JObject.Load method can take a JsonReader as a parameter so we can change its settings without modifying the source code.
Same here.
I wanted to parse a part of object in a JSON string and sadly I wrote something like this:
Made up #1969 to work this around. Hope it will be accepted.