当我试图在iOS SWIFT中调用api时,为什么涉及另一种语言的特殊字符会导致崩溃?
这是罪魁祸首字符串,参数name=solsssㅗ当我试图在iOS SWIFT中调用api时,为什么涉及另一种语言的特殊字符会导致崩溃?,ios,swift,alamofire,Ios,Swift,Alamofire,这是罪魁祸首字符串,参数name=solsssㅗ Alamofire.request(todoEndpoint) .responseJSON { response in // check for errors guard response.result.error == nil else { // got an error in getting the data, n
Alamofire.request(todoEndpoint)
.responseJSON { response in
// check for errors
guard response.result.error == nil else {
// got an error in getting the data, need to handle it
print("error calling GET on \(todoEndpoint)")
print(response.result.error!)
DispatchQueue.main.async
{
self.activityView.isHidden = true
self.activityView.stopAnimating()
}
return
}
所以我在URL中得到的错误总是无效的。如果我不使用任何特殊字符,它就可以正常工作。您可以使用字符串url-
let urlWithSpecialCharacter = url.addingPercentEncoding( withAllowedCharacters: .urlQueryAllowed)
我认为您必须将特殊字符:参数转换为url需要进行url编码,这是为了消除url中常见的保留字符的可能冲突,例如“?,$,/”url在提交/读取之前对url进行编码/解码。