【发布时间】:2016-08-29 05:50:13
【问题描述】:
如何在 iOS 中通过 AFNetworking 以 JSON 格式发送NSDate? Json 请求 -
{
"from_date" : "11/11/2014",
"to_date" : "11/11/2017"
}
代码 -
// Formats the date chosen with the date picker.
- (NSString *)formatDate:(NSDate *)date
{
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateStyle:NSDateFormatterShortStyle];
[dateFormatter setDateFormat:@"dd'/'MM'/'yyyy"];
NSString *formattedDate = [dateFormatter stringFromDate:date];
return formattedDate;
}
- (void)updateToDateField:(id)sender
{
UIDatePicker *picker = (UIDatePicker*)toDateField.inputView;
toDateField.text = [self formatDate:picker.date];
}
// Storing the to date in NSString
dashboard.toDateString = toDateField.text;
【问题讨论】:
-
你能展示一些你期望的输出吗
-
@Anbu.Karthik - 我想发送包含日期的 JSON 请求,我在 Postman 中得到了正确的响应,但是当我运行我的代码时,afnetworking 给出错误 - 状态 500。
-
好的没问题你能显示代码吗
-
@NDoc - 我想,我的日期格式化程序和你的一样,而且我正在创建字典。
标签: ios json nsdate afnetworking