4

从 iPhone 应用程序中,我必须将日期作为参数发送到使用 C#、.NET 和 JSON 实现服务器解析逻辑的 web 服务方法。

在我的 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];

我收到错误消息:

反序列化 DashboardDataContract.Contracts.DashboardInputParams 类型的对象时出错。DateTime 内容 '2013-04-04T12:00:00Z' 不以 JSON 所需的 '/Date(' 开头并以 ')/' 结尾。'。

我尝试了不同的日期格式。

4

3 回答 3

6
于 2013-04-04T11:39:31.437 回答
0

Most efficient way to send NSDate to server is to get the timestamp. You can basically get it with

NSTimeInterval timestamp = [[NSDate date] timeInvervalSince1970];
于 2013-04-04T12:05:29.510 回答
0

You can create a category method in NSDate

- (NSString *)jsonDateString
{
    NSTimeInterval seconds = [self timeIntervalSince1970];
    return [NSString stringWithFormat:@"/Date(%.0f+0000)/",seconds*1000];

}
于 2013-04-04T12:11:39.557 回答