在Swift中URL编码

在Swift中URL编码用到的是String的方法

func addingPercentEncoding(withAllowedCharacters allowedCharacters: CharacterSet) -> String?

用法:

let str = "{urlencode}"
print(str.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed))

编码后的结果:%7burlencode%7d

在Swift中URL解码

在Swift中URL解码用到的是String的属性

var removingPercentEncoding: String? { get }

用法:

let str = "%7burldecode%7d"
print(str.removingPercentEncoding) 

解码后得到的结果是:{urldecode}

04-18 17:50
查看更多