【发布时间】:2016-01-16 11:31:21
【问题描述】:
我正在尝试在我的应用中使用 Alamofire 进行 API 调用,但我收到了一个奇怪的错误。
'There was an error deserializing the object of type Tucson.Geocaching.WCF.API.CreateTrackableLogRequestV1. DateTime content '\/Date(1452942271163+0500)\/' does not start with '\/Date(' and end with ')\/' as required for JSON.'
在Website of the API 上说日期格式必须是这样的:"\/Date(928174800000-0700)\/"
我的代码:
postTBLog("GSYCNP", text: "Test", date: "\\/Date(928174800000-0700)\\/", logType: 48)
func postTBLog (code: String, text: String, date: String, logType: Int) -> Bool {
if let apiKey = apiKey {
let url = "https://api.groundspeak.com/LiveV6/geocaching.svc/CreateTrackableLog"
let parameters:[String : AnyObject] = ["AccessToken":apiKey, "TrackingNumber":code, "UTCDateLogged": date, "Note":text, "LogType":logType]
Alamofire.request(.POST, url, parameters: parameters, encoding: .JSON).responseString { response in
print(response)
}
return true
} else {
return false
}
}
我已经尝试了不同的方法,但没有任何效果。如果你能帮助我,我会很高兴,谢谢。
【问题讨论】:
-
你尝试过什么?您是否尝试过仅给出 API 文档中的确切示例?您是否尝试过故意为前导/尾随部分和日期赋予错误?您是否尝试过不转义反斜杠?
-
@bill 我已经尝试过 API 和其他日期格式中的示例,但没有任何效果。
-
加单引号 Date('....')
-
@JoeHuang 也不行
-
您需要明确说明“没有任何效果”。总是同样的信息?你试过不逃避吗? API 文档中是否有完整的示例,您是否尝试过,与您的代码隔离?
标签: .net json swift api alamofire