我有这个错误
错误域= NSCocoaErrorDomain代码= 3840“垃圾结束。” UserInfo = {NSDebugDescription =结尾处的垃圾。}
这是我的快速代码:
var exercise:String = ""
for value in numberOfExercisesArray{
exercise = exercise + value.text! + ","
}
if exercise.characters.last == ","{
exercise.removeAtIndex(exercise.endIndex.predecessor())
}
我要发布的字符串(练习)就在这个上下文中:“替补,5,100”但是由于上面的错误我无法通过这个字符串下面是我如何连接到我的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();
如何解决此错误谢谢
进一步澄清这里是我的PHP代码:
$exercise = htmlentities($_POST["exercise"]);
$test1 = "1,2,3";
$array = explode (",",$test1);
$array2 = explode (",",$exercise);
$returnValue = array();
$dao = new MySQLDao();
$dao->openConnection();
foreach (array_combine($array, $array2) as $value => $value2) {
$userDetails = $dao->insertExercise($value, $value2);
}