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

时间:2018-08-13 05:56:21

标签: ios swift alamofire

这是罪魁祸首字符串和参数名= 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错误总是无效的。如果我不带任何特殊字符就可以使用它。

1 个答案:

答案 0 :(得分:1)

您可以尝试使用String url-

let urlWithSpecialCharacter = url.addingPercentEncoding( withAllowedCharacters: .urlQueryAllowed)