从iPhone应用程序,我必须将日期作为参数发送到webservice方法,其中服务器解析逻辑使用C#,.NET和JSON实现.
在我的iPhone应用程序中,我将日期格式化为:
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setTimeZone:[NSTimeZone timeZoneWithName:@"UTC"]];
[dateFormatter setDateFormat:@"yyyy'-'MM'-'dd'T'HH':'mm':'ss'Z'"];
Nsstring *myDateString = [dateFormatter stringFromDate:SentOn];
我收到错误:
There was an error deserializing the object of type DashboardDataContract.Contracts.DashboardInputParams. DateTime content ‘2013-04-04T12:00:00Z’ does not start with ‘/Date(‘ and end with ‘)/’ as required for JSON.’.
我尝试了不同的日期格式.
解决方法:
默认情况下,JSON.Net库将使用ISO Date格式发出所有日期,例如“2012-05-09T00:00:00Z”,但Microsoft的日期JSON格式化程序将使用Microsoft自己的格式“/ Date(xxxxxxxxxxxx)/”发出.
你可以试试这个:
unsigned long long time=(([[NSDate date] timeIntervalSince1970])*1000);
Nsstring* dateTimetosend= [Nsstring stringWithFormat:@"/Date(%lld)/",time];