ios 上 如何像PHP那样有 urldecode 函数 如何实现
1个回答
推荐于2016-02-02
展开全部
urlencode的目的是传输url安全的字符
比如中文, 例如"神"变成%C9%F1(如果是utf8则是%E7%A5%9E)
各种非字母的符号也会对应做编码, 比如& == %26.
而对应的urldecode就是一个还原的过程. 也就是说把%26还原为&. 中文同理
所以按说... 是不会有从 "䴙 使用urldecode后变成 䴅" 的情况. 至少从urlencode的原理上是这样.
至于你问的urldecode
参见NSURL.h, 其中
@interface NSString (NSURLUtilities)
/* Adds all percent escapes necessary to convert the receiver into a legal URL string. Uses the given encoding to determine the correct percent escapes (returning nil if the given encoding cannot encode a particular character). See CFURLCreateStringByAddingPercentEscapes in CFURL.h for more complex transformations
*/
- (NSString *)stringByAddingPercentEscapesUsingEncoding:(NSStringEncoding)enc;
/* Replaces all percent escapes with the matching characters as determined by the given encoding. Returns nil if the transformation is not possible (i.e. the percent escapes give a byte sequence not legal in the given encoding). See CFURLCreateStringByReplacingPercentEscapes in CFURL.h for more complex transformations
*/
- (NSString *)stringByReplacingPercentEscapesUsingEncoding:(NSStringEncoding)enc;
@end
比如中文, 例如"神"变成%C9%F1(如果是utf8则是%E7%A5%9E)
各种非字母的符号也会对应做编码, 比如& == %26.
而对应的urldecode就是一个还原的过程. 也就是说把%26还原为&. 中文同理
所以按说... 是不会有从 "䴙 使用urldecode后变成 䴅" 的情况. 至少从urlencode的原理上是这样.
至于你问的urldecode
参见NSURL.h, 其中
@interface NSString (NSURLUtilities)
/* Adds all percent escapes necessary to convert the receiver into a legal URL string. Uses the given encoding to determine the correct percent escapes (returning nil if the given encoding cannot encode a particular character). See CFURLCreateStringByAddingPercentEscapes in CFURL.h for more complex transformations
*/
- (NSString *)stringByAddingPercentEscapesUsingEncoding:(NSStringEncoding)enc;
/* Replaces all percent escapes with the matching characters as determined by the given encoding. Returns nil if the transformation is not possible (i.e. the percent escapes give a byte sequence not legal in the given encoding). See CFURLCreateStringByReplacingPercentEscapes in CFURL.h for more complex transformations
*/
- (NSString *)stringByReplacingPercentEscapesUsingEncoding:(NSStringEncoding)enc;
@end
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询