With my need to exchange data between a ASP.NET and PHP web applications, I decided to use JSON. The .NET team did a good job by integrating JSON de/serialization into the language (NET 3.5) but they decided not to follow JSON specifications for some good reasons. Serializing an object that has a DateTime property will insert a string that won’t be understood by json_decode of PHP.

On the site of JSON, there is no such thing as a date type.  I have taken the ISO 8601 path which is my preferred date format (MySQL and Swedish Locale standard)

Consider the following class:

  1. [DataContract]
  2. public class Person
  3. {
  4. [DataMember]
  5. public DateTime DateOfBirth { set; get; }
  6. [DataMember]
  7. public string Names { set; get; }
  8. }

By Serializing it you will get something like

{”DateOfBirth” : “\/Date(1210408872000+0200)\/”, “Names” : “Kavuna ka Lyaziga”}

That Date is not defined as a JSON type. In case your JSON will be used directly by JavaScript or .NET (C#, VB) you will not need to write extra codes.