Note that there are some explanatory texts on larger screens.

plurals
  1. POJson ISO Date not deserialized as DateTime object
    primarykey
    data
    text
    <p>I am creating a multiplatform application that works on .net/mono and uses Newtonsoft.Json to serialize information.</p> <p>All worked well until I tried to send information between the machines with exactly the same version of Newtonsoft.Json.dll.</p> <p>What turned out it that dates were properly serialized in the ISO format like that: <strong>"2013-02-08T12:11:39Z"</strong>, but when I try to deserialize them on Mac OS I get a string back instead of DateTime object!</p> <p>I did some experiments using the serializer settings:</p> <pre><code>private static readonly JsonSerializerSettings jsonSettings = new JsonSerializerSettings { DateTimeZoneHandling = DateTimeZoneHandling.Utc, DateFormatHandling = DateFormatHandling.IsoDateFormat, DateParseHandling = DateParseHandling.DateTime, Converters = new JsonConverter [] { new Newtonsoft.Json.Converters.IsoDateTimeConverter { DateTimeFormat = "yyyy-MM-ddTHH:mm:ssZ" } } }; JsonConvert.DeserializeObject&lt;object&gt; ("\"2013-02-08T10:11:51Z\"", jsonSettings); </code></pre> <p>But the result is till exactly the same string <strong>"2013-02-08T10:11:51Z"</strong>. I did some more experiments and it turned out that using exactly the same settings I am not able to serialize and deserialize the date like that:</p> <pre><code>JsonConvert.DeserializeObject&lt;object&gt;(JsonConvert.SerializeObject(DateTime.Now, jsonSettings), jsonSettings); </code></pre> <p>I still get a string representing the ISO date. After that I tried this too:</p> <pre><code>JsonConvert.DeserializeObject&lt;object&gt;(JsonConvert.SerializeObject(DateTime.Now)); </code></pre> <p>And now I get the proper DateTime object as a result. But running the following code shows that the way the date is serialized is not exactly the ISO format:</p> <pre><code>JsonConvert.SerializeObject(DateTime.Now); </code></pre> <p>Returns something like <strong>"\"2013-02-08T12:22:25.974177+02:00\""</strong> which is not standart and will not be able to work for communication.</p> <p>The weirdest part is that I had a client wit a Mac that had no such problems. I am starting to think that this is somehow related to the OS, but then wouldn't the exact format specified by me fix that?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload