1

After much head scratching as to why my returned Json string is breaking JSON.parse, I have realized that it is the returned dates that it doesn't like.

.net property:-

 [JsonProperty("start")]
 [JsonConverter(typeof(JavaScriptDateTimeConverter))]
 public DateTime Start
 {
 get { return _start; }
 set { _start = value; }
 }

Output Json String from web service:-

"{\"id\":9815,\"start\":new Date(1286535600000),\"end\":new Date(1286537400000),\"title\":\"Title of meeting\",\"owner\":\"D\",\"contactdetails\":\"David\",\"room\":{\"title\":\"Small Meeting Room\",\"id\":2}}"

Any help appreciated.

asked Aug 10, 2010 at 12:09

2 Answers 2

1

Thanks for the response James. In the end I used a different converter with Json.net and everything appears to work as planned. It does essentially return a formatted date string, but I can decorate the current DateTime property instead of using string in my .net class:-

 [JsonProperty("start")]
 [JsonConverter(typeof(IsoDateTimeConverter))]
 public DateTime Start
 {
 get { return _start; }
 set { _start = value; }
 }
answered Aug 10, 2010 at 15:03
0

I tend to return dates as strings, so just do:

new Date(1286535600000).toString("MM/dd/yyyy") for example.

So, you may want to have your property with a getter that returns a string, so you can have it formatted, and perhaps the setter should also be a string, to simplify what is being passed back and forth from the page.

answered Aug 10, 2010 at 12:13

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.