2016-01-16 45 views
0

我試圖在應用程序中與Alamofire進行API調用,但是出現了一個奇怪的錯誤。Swift - 錯誤日期格式(JSON .NET)

'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 
    } 
} 

我已經嘗試不同的東西,但沒有接縫的工作。如果你能幫助我,我會很高興。

+0

你嘗試過什麼東西?您是否嘗試過從API文檔中給出確切的示例?你有沒有嘗試給它的前導部分和尾部部分故意錯誤?你有沒有嘗試過逃避反斜槓? –

+0

@bill我試着從API和其他日期格式的例子,但沒有任何工作。 – NMAC427

+0

添加單引號日期('....') –

回答

0

它的工作我轉身"\\/Date(928174800000-0700)\\/""/Date(928174800000)/"