Home > Mobile >  How to remove special characters from url?
How to remove special characters from url?

Time:02-21

let ids = [String: [String]]

ids=[E66abef1c-4462-4g62-bcc5-5ae10547104c", 56efcf8c-6977-430d-b3ec-4ae80547101c"]

After appended and passing url params, response failing in response structure special symbol added in -> [%%

https://baseUrl/endpoint?ids=4566abef1c-4462-4g62-bcc5-5ae10547104c,1256efcf8c-6977-430d-b3ec-4ae80547101c

How to remove "] 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

CodePudding user response:

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: ",") }

CodePudding user response:

"...How to remove "] from url? ". Try this:

 let ids = "[E66abef1c-4462-4g62-bcc5-5ae10547104c", 56efcf8c-6977-430d-b3ec-4ae80547101c"]"
 let cleanUrl = ids.replacingOccurrences(of: ""]", with: "")
 print("\n---> cleanUrl: \(cleanUrl) \n")
  • Related