json.netswiftalamofire

Swift - Wrong date format (JSON .NET)


I'm trying to make a API call with Alamofire in my app, but I get a strange error:

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

On the Website of the API it say the date format must be like this: "\/Date(928174800000-0700)\/"

My code:

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

I have already tried different things but nothing seamed to work. I would be very happy if you could help me.


Solution

  • It worked after I turned "\\/Date(928174800000-0700)\\/" to "/Date(928174800000)/"