'How to remove special characters from url?
let ids = [String: [String]]
ids=%5B%4566abef1c-4462-4g62-bcc5-5ae10547104c%22,%20%1256efcf8c-6977-430d-b3ec-4ae80547101c%22%5D
After appended and passing url params, response failing in response structure special symbol added in -> %5B%%
https://baseUrl/endpoint?ids=4566abef1c-4462-4g62-bcc5-5ae10547104c,1256efcf8c-6977-430d-b3ec-4ae80547101c
How to remove %22%5D from url?
Here Code:
let parms: [String: [String]]
let urlString = "\(baseUrl)/\(endpoint)"
Connector.requestSwiftyJson(
url: urlString,
requestType: .get,
withParams: parms,
loader: false
) { json, response, error in
Solution 1:[1]
you can remove unwanted characters by adapting the parameters right before passing it into the parser like:
let adaptedParams = params.reduce(into: [String: String]()) { $0[$1.key] = $1.value.joined(separator: ",") }
Solution 2:[2]
"...How to remove %22%5D from url? ". Try this:
let ids = "%5B%4566abef1c-4462-4g62-bcc5-5ae10547104c%22,%20%1256efcf8c-6977-430d-b3ec-4ae80547101c%22%5D"
let cleanUrl = ids.replacingOccurrences(of: "%22%5D", with: "")
print("\n---> cleanUrl: \(cleanUrl) \n")
You can also remove all percent encoding using this:
if let cleanUrl = ids.replacingOccurrences(of: "%5B", with: "") // [
.replacingOccurrences(of: "%5D", with: "") // ]
.replacingOccurrences(of: "%22", with: "") // "
.removingPercentEncoding { // other encoding
print("\n---> cleanUrl: \(cleanUrl) \n")
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Mojtaba Hosseini |
| Solution 2 |
