您好我正在尝试向Google Calendar API V3发出请求并设置minDate值。根据Google API文档,日期需要进行编码。见:https://developers.google.com/google-apps/calendar/v3/reference/events/list
查看本课题中的解释:Swift - encode URL我可以通过以下方式实现这一目标:
// todayString = "2014-11-10T23:15:25+1300"
var escapedTodayString:NSString! = todayString.stringByAddingPercentEncodingWithAllowedCharacters(.URLHostAllowedCharacterSet())
然而,这仅编码部分字符串,输出为: 2014-11-10T23%3A15%3A25 + 1300 这在请求中失败。我需要的输出是: 2014-11-10T22%3A38%3A48%2B1300
当我使用所需的输出发出请求时,它按预期工作。
我怎样才能达到这种级别的编码?
答案 0 :(得分:0)
您可以通过以下代码实现这一目标。从允许的字符中删除“+”
var todayString = "2014-11-10T23:15:25+1300"
var characters = NSCharacterSet.URLHostAllowedCharacterSet().mutableCopy() as NSMutableCharacterSet
characters.removeCharactersInString("+")
var escapedTodayString:NSString! = todayString.stringByAddingPercentEncodingWithAllowedCharacters(characters)