以下URL
需要在Swift 3中进行编码
https://maps.googleapis.com/maps/api/geocode/json?address=madhapur.%20Hyderabad
答案 0 :(得分:1)
您可以像这样对URL进行编码和解码。
let stringURL = "https://maps.googleapis.com/maps/api/geocode/json?address=madhapur Hyderabad"
if let encodeURL = stringURL.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed) {
print(encodeURL)
let decodeURL = encodeURL.removingPercentEncoding
print(decodeURL)
}
输出
https://maps.googleapis.com/maps/api/geocode/json?address=madhapur%20Hyderabad
Optional("https://maps.googleapis.com/maps/api/geocode/json?address=madhapur Hyderabad")
答案 1 :(得分:0)
您可以使用 removedPercentEncoding
var str = "https:%2F%2Fmaps.googleapis.com%2Fmaps%2Fapi%2Fgeocode%2Fjson%3Faddress=madhapur.%20Hyderabad"
str = str.removingPercentEncoding!
结果: - https://maps.googleapis.com/maps/api/geocode/json?address=madhapur. Hyderabad