0

here is my 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 is my deserializer:

var serializer = new JavaScriptSerializer();
var reportParams = serializer.Deserialize<ReportAllMediaDetailsParams>(json);

the date that is coming from json is:

"{\"profileID\":\"41\",\"organisationID\":\"2252\",\"startDate\":\"01/01/1970\",\"endDate\":\"01/01/1970\"}"
Matt Johnson-Pint
  • 230,703
  • 74
  • 448
  • 575
Farhad-Taran
  • 6,282
  • 15
  • 67
  • 121

1 Answers1

3
  • Don't use JavaScriptSerializer, use Json.Net instead.

  • Don't use locale specific formats such as MM/dd/yyyy or dd/MM/yyyy in JSON. For example, does 1/4/2013 represent the first day of April? Or the fourth day of January? There's no way to know.

  • Use ISO8601 format instead. It is culture-invariant, so there is no ambiguity. In ISO format, you have 2013-01-04, which is always yyyy-mm-dd so there is no ambiguity. A full datetime would be 2013-01-04T05:30:27.123 for example.

  • Coming from C#, use DateTime.ToString("o") to get this format - or just use Json.Net which automatically serializes DateTime and DateTimeOffset using the ISO format.

Matt Johnson-Pint
  • 230,703
  • 74
  • 448
  • 575