2
我有這樣的錯誤swift錯誤:代碼= 3840「結束垃圾」。
Error Domain=NSCocoaErrorDomain Code=3840 "Garbage at end." UserInfo={NSDebugDescription=Garbage at end.}
這裏是我的SWIFT代碼:
var exercise:String = ""
for value in numberOfExercisesArray{
exercise = exercise + value.text! + ","
}
if exercise.characters.last == ","{
exercise.removeAtIndex(exercise.endIndex.predecessor())
}
我要發佈(運動)的字符串是在這種情況下:「臥推,5100」 不過我不能讓這串去,因爲上面 錯誤的,通過下面是我如何連接到我的PHP/SQL服務器:
let myURL = NSURL(string: "http://localhost:8888/saveWorkout.php");
let request = NSMutableURLRequest(URL:myURL!);
request.HTTPMethod = "POST";
let postString = "exercise=\(exercise)";
request.HTTPBody = postString.dataUsingEncoding(NSUTF8StringEncoding);
let task = NSURLSession.sharedSession().dataTaskWithRequest(request){
data, response, error in
if error != nil {
print("error=\(error)")
return
}
do{
let json = try NSJSONSerialization.JSONObjectWithData(data!, options: NSJSONReadingOptions.AllowFragments) as? NSDictionary
if let parseJSON = json{
let resultValue = parseJSON["status"] as! String!;
print("result: \(resultValue)")
if(resultValue == "Success"){
print("worked")
}
else{
print("not worked")
}
}
}
catch { print(error) }
}
task.resume();
我該如何解決這個錯誤 謝謝