c# - JavaScriptSerializer won't recognize date string as DateTime? -


here model:

public class reportallmediadetailsparams     {         public int profileid  { get; set; }         public int organisationid { get; set; }         public datetime startdate { get; set; }         public datetime enddate { get; set; } } 

here deserializer:

var serializer = new javascriptserializer(); var reportparams = serializer.deserialize<reportallmediadetailsparams>(json); 

the date coming json is:

"{\"profileid\":\"41\",\"organisationid\":\"2252\",\"startdate\":\"01/01/1970\",\"enddate\":\"01/01/1970\"}" 

  • don't use javascriptserializer, use json.net instead.

  • don't use locale specific formats such mm/dd/yyyy or dd/mm/yyyy in json. example, 1/4/2013 represent first day of april? or fourth day of january? there's no way know.

  • use iso8601 format instead. culture-invariant, there no ambiguity. in iso format, have 2013-01-04, always yyyy-mm-dd there no ambiguity. full datetime 2013-01-04t05:30:27.123 example.

  • coming c#, use datetime.tostring("o") format - or use json.net automatically serializes datetime , datetimeoffset using iso format.


Popular posts from this blog

How to calculate SNR of signals in MATLAB? -

c# - Attempting to upload to FTP: System.Net.WebException: System error -

ios - UISlider customization: how to properly add shadow to custom knob image -