iOS URL编码 解码

1.URL编码

NSString *encodeURL = [url stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

2.URL解码

NSString *decodeURL = [url stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

ios 9.0中已经替换此方法

//encode URL编码
NSString *str = [url stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];

//decode URL解码
NSString *decodedURL = [url stringByRemovingPercentEncoding];

你可能感兴趣的:(iOS URL编码 解码)