我有这个错误
错误的Domain=NSCocoaErrorDomain Code=3840“垃圾在结尾。”UserInfo={NSDebugDescription=Garbage在末尾.}
这是我的快速密码:
var exercise:String = ""
for value in numberOfExercisesArray{
exercise = exercise + value.text! + ","
}
if exercise.characters.last == ","{
exercise.removeAtIndex(exercise.endIndex.predecessor())
}我想要发布的字符串(练习)在这个上下文中:"bench press,5,100“然而,由于下面的错误,我无法通过这个字符串连接到我的php/sql server:
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();我如何修复这个错误谢谢
发布于 2016-03-06 09:58:20
您的问题是,您正在使用Json,而当您试图解析json时,实际上您并不是很好地解析它,Json可以解析为Dictionary或Array,检查您的json响应尝试在任何在线json解析器中解码它,看看它是什么样的,
https://stackoverflow.com/questions/35675403
复制相似问题