0

I am using JSON.net for Compact Framework - version 3.5r8. The referenced file is: Newtonsoft.Json.Compact.dll.

If I have a JSON object with a date/time in ISO 8601 format, such as:

{
   "name": "TestObject",
   "timestamp": "2017-08-04T13:39:16+01:00"
}

And I de-serialize this using JsonConvert.DeserializeObject<TestObject>(response), C# parses the timestamp property to a DateTime as expected, however the time is parsed at 05:39AM so there is clearly a time zone issue in play causing the parsing to be out by 8 hours from UTC.

I appreciate the "full" / latest versions of JSON.net do have options we can pass by way of JsonSerializerSettings to alter the date time zone handling but none of these seem to be available with JSON.net Compact.

How can I cause the time stamp to be parsed in UTC as expected?

1 Answer 1

1

Yes you can set timezone.

var json = JsonConvert.DeserializeObject<TestObject>(response, new JsonSerializerSettings
           {
               DateTimeZoneHandling = DateTimeZoneHandling.Utc
           });
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for the reply but as mentioned, there is no DateTimeZoneHandling options exposed in this version of JSON.net.
Unfortunately not, the only properties available in that namespace are here: imgur.com/a/RiqAy

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.