Good afternoon I have the following error when consuming a web service by POST: Error Domain = NSCocoaErrorDomain Code = 3840 "JSON text did not start with array or object and option to allow fragments not set."
the error comes out just at the time of json that brings me the serviceWeb, attached a fragment of the code thanks:
let length="123414" latitude latitude="123414"
let dir = Helpers.REQUESTAPIURL + "/uploadImage"
let url:NSURL = NSURL (string: dir)!
let bodyData = "idUsuario=\(String(idUsuario!))&idLugar=\(idLugar)&img=\(base64Img)&longitud=\(longitud)&latitud=\(latitud)"
let request:NSMutableURLRequest = NSMutableURLRequest(URL:url)
request.HTTPMethod = "POST"
request.HTTPBody = bodyData.dataUsingEncoding(NSUTF8StringEncoding);
let session = NSURLSession.sharedSession()
let task = session.dataTaskWithRequest(request, completionHandler: {data, response, error -> Void in
if (error != nil){
print(error!.localizedDescription)
}
else{
// let nsdata: NSData = NSData(data: data!)
if(data != ""){
do{
let json = try NSJSONSerialization.JSONObjectWithData(data!, options: NSJSONReadingOptions.MutableContainers)
self.msn = String(json["mensaje"])
}catch {
print(error)
self.msn = "Error al serealizar JSON"
dispatch_async(dispatch_get_main_queue()) {
self.mostrarAlert()
}
}
}
else{
self.msn = "Error, verifique los datos"
}
self.mostrarAlert()
}
})
task.resume()