编程语言
首页 > 编程语言> > c# – 将日期时间从iPhone应用程序发送到Web服务

c# – 将日期时间从iPhone应用程序发送到Web服务

作者:互联网

从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];

标签:json,c,ios,nsdate,nsdateformatter
来源: https://codeday.me/bug/20190529/1178871.html