Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
当我试图在iOS SWIFT中调用api时,为什么涉及另一种语言的特殊字符会导致崩溃?_Ios_Swift_Alamofire - Fatal编程技术网

当我试图在iOS SWIFT中调用api时,为什么涉及另一种语言的特殊字符会导致崩溃?

当我试图在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

这是罪魁祸首字符串,参数name=solsssㅗ

 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进行编码/解码。