How to parse JSON to receive a Date object in JavaScript?
Posted
by
Piotr Owsiak
on Stack Overflow
See other posts from Stack Overflow
or by Piotr Owsiak
Published on 2010-12-22T17:13:00Z
Indexed on
2010/12/22
17:54 UTC
Read the original article
Hit count: 274
I have a following piece of JSON:
\/Date(1293034567877)\/
which is a result of this .NET code:
var obj = DateTime.Now;
var serializer = new System.Web.Script.Serialization.JavaScriptSerializer();
serializer.Serialize(obj).Dump();
Now the problem I am facing is how to create a Date object from this in JavaScript. All I could find was incredible regex solution (many containing bugs).
It is hard to believe there is no elegant solution as this is all in JavaScrip, I mean JavaScript code trying to read JSON (JavaScript Object Notation) which is supposed to be a JavaScript code and at this moment it turns out it's not cause JavaScript cannot do a good job here.
I've also seen some eval solutions which I could not make to work (besides being pointed out as security threat).
Is there really no way to do it in an elegant way?
Similar question with no real answer:
How to parse ASP.NET JSON Date format with GWT
© Stack Overflow or respective owner