I use .NET WCF + RESTful for developing the service and WizTools.org RESTClient for tesing. I have a problem about receiving JSON datetime from the client. They are always DateTime.MinValue.
Here is my DataContract
[DataContract(Name = "origin")]
public class OriginObject
{
[DataMember(Name = "airport")]
public string Airport { get; set; }
[DataMember(Name = "oddt")]
public DateTime Oddt { get; set; }
[DataMember(Name = "eddt")]
public DateTime Eddt { get; set; }
}
[DataContract(Name = "destination")]
public class DestinationObject
{
[DataMember(Name = "airport")]
public string Airport { get; set; }
[DataMember(Name = "odat")]
public DateTime Odat { get; set; }
[DataMember(Name = "edat")]
public DateTime Edat { get; set; }
}
and here is my testing JSON (please ignore "acid", just only "destination" and "origin")
{
"acid" : "AAA1",
"destination" : {
"airport" : "VVVV",
"eddt" : "2013-03-05T20:20:31.000Z",
"oddt" : "/Date(1362489941)/"
},
"flightPlanState" : "ACTIVE",
"origin" : {
"airport" : "XXXX",
"edat" : "\/Date(1362499081)\/",
"odat" : "1362498721"
}
}
all of 4 datetime styles above are min-value in code-behind (just only datetime, both "airport" fields have normal values).
DateTime is not well defined with Json, though the "eddt" value looks like a value which ought to be parsable by a common .Net Json serializer.
My suggestion is to use string properties, and add extra GetOddt() etc. functions which parse the string values to DateTime values; if required, add also SetOddt() etc. functions, and do not forget to update the corresponding string values!
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.