iOS中如何对URL的param强制encode,不影响前面的http…等

如何encode:

let urlStrEncode = urlStr.stringByAddingPercentEscapesUsingEncoding(NSUTF8StringEncoding)

或者

let urlStrEncode = urlStr.stringByAddingPercentEncodingWithAllowedCharacters( NSCharacterSet.URLQueryAllowedCharacterSet())

顺道再贴下如何decode:

let urlStrDecode = urlStrEncoded.stringByRemovingPercentEncoding

Leave a Reply

Your email address will not be published.