2

So I've used a third party JSON serializer named Json-Net. It converts my DateTime objects into something like new Date(2031231023912) inside a JSON string.

I, however, can't get any Javascript JSON parsers to parse it, since it is considered invalid JSON. Any ideas around it?

I guess I could manually send back the ticks from the webservice I am hitting but that would be a pain. Hopefully there is a workaround.

1 Answer 1

1

The JSON format has no intrinsic concept of "date" as a data type. You have to know where the date values are in your deserialized objects, and you have to write the code that finds those and instantiates dates. You can represent the date as an epoch time or as a calendar string; it depends on the application (and it does make a difference).

Representing a date as a string like, "new Date(123456789)" seems like a particularly bad way to do things. It'd be simpler to just store the value.

Sign up to request clarification or add additional context in comments.

2 Comments

Yeah looks like the author admits it is invalid JSON. Wonder why he didn't just convert it to ticks?
Ah well if it doesn't even quote it, then it's definitely not going to work :-)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.