gpt4 book ai didi

php - 快速错误 : Code=3840 "Garbage at end."

转载 作者:可可西里 更新时间:2023-11-01 02:17:29 27 4
gpt4 key购买 nike

我有这个错误

Error Domain=NSCocoaErrorDomain Code=3840 "Garbage at end." UserInfo={NSDebugDescription=Garbage at end.}

这是我的快速代码:

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();

如何修复这个错误谢谢

最佳答案

你的问题是,你正在使用 Json,当你尝试解析 json 实际上你并没有完美地解析它,Json 可以解析为字典或数组,检查你的 json 响应尝试在任何在线 json 解析器中解码它,看看它的样子,

  • 复制你的服务器响应(json)
  • 在 google 中搜索(在线 json 格式化程序)
  • 过去看看

关于php - 快速错误 : Code=3840 "Garbage at end.",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35675403/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com