coolboyjules coolboyjules - 2 months ago 9
C# Question

Can't parse JSON data to .NET DateTime

It's pretty simple. I have a string

string s = "/Date(1474408920000)/"


And I want to convert it to a date:

DateTime date = JsonConvert.DeserializeObject<DateTime>(s);


But I get the error:

"Error parsing comment. Expected: *, got D. Path '', line 1, position 1."

What's going on here?

Thanks for your help!

L.B L.B
Answer

Your json string is not valid but can easily be fixed by surrounding it with "

string s = @"""/Date(1474408920000)/""";

Now DateTime date = JsonConvert.DeserializeObject<DateTime>(s); will work