ios - 当我尝试在 iOS SWIFT 中调用 api 时,为什么涉及来自另一种语言的特殊字符会导致崩溃?
问题描述
这是罪魁祸首字符串和参数名称=solsssㅗ</p>
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 中得到错误总是无效的。如果我在没有任何特殊字符的情况下使用它,它就可以正常工作。
解决方案
您可以使用 String url 尝试此操作 -
let urlWithSpecialCharacter = url.addingPercentEncoding( withAllowedCharacters: .urlQueryAllowed)
推荐阅读
- c# - 嵌套查询字符串编码器/解码器 c#
- c++ - C++/Asio:使用 async_write 发送数据时崩溃
- mysql - Yii2 迁移灵活的数据库引擎
- html - 带有多个链接和按钮的 HTML 选择框
- r - 使用多个变量在 lm() 中过滤
- .net - 如何在 UIPath 中使用正则表达式匹配替换
- python - How to handle google website data security pop up?
- python - Is there a way that feeding a input to layers parallelly in PyTorch?
- sql - 同一张表上的多个连接相乘计数
- java - Returning a subclass as type interface