I have a strange problem. I am using the JSON Framework from newtonsoft. But it is changing the date formatting of some of my strings.
I transfer some strings within a JSON string like this:
{"MyStrings":["Hello","World"]}
I have this matching DTO class:
public class Test
{
public List<string> MyStrings { get; set; }
}
Now I want to deserialize it into my DTO class like this:
string content = @"{""MyStrings"":[""2016-10-07T13:37:01.4209934Z"",""2016-10-07T13:37:01.4209934Z""]}";
var obj = JObject.Parse(content);
var test = obj.ToObject<Test>();
You see, in the JSON string there are strings that coincidentally look like a datetime value.
{
"MyStrings":
["2016-10-07T13:37:01.4209934Z",
"2016-10-07T13:37:01.4209934Z"]
}
If we investigate the string values, we get: "10/07/2016 13:37:01".
Something completely different.
What is going on here? I did not change the default behavior. JSON.NET is changing the string values on his own. Why is this framework changing my string values? I want to leave it as it is - a string.
is this a bug in JSON.NET, or can I control this behavior with a special setting?
I tried all enum settings in the JsonSerializerSettings.
-DateParseHandling.None
-DateFormatString
-DateFormatHandling
-DateTimeZoneHandling
Nothing worked.
.ToStringmethod over them. Quite weird it looks like it's doing some extra unwanted work...((JValue)DateTime.Now).ToString()outputs in current culture format rather than invariant ISO 8601 format is a bug.