簡體   English   中英

當我嘗試在iOS SWIFT中調用api時,為什么涉及另一種語言的特殊字符會導致崩潰?

[英]Why is involving a special character from another language creating a crash when I try to call api in iOS SWIFT?

這是罪魁禍首字符串,參數名稱= 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中收到錯誤消息,始終是無效的。 如果我不帶任何特殊字符使用它,則效果很好。

您可以嘗試使用String url-

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM