美文网首页
ios中URL字符串的URLencode与URLdecode

ios中URL字符串的URLencode与URLdecode

作者: 奶茶007 | 来源:发表于2016-12-13 16:50 被阅读394次

url字符串中具有特殊功能的特殊字符的字符串,或者中文字符,作为参数用GET方式传递时,需要用urlencode处理一下

、、、
//URLEncode

+(NSString*)encodeString:(NSString*)unencodedString{

// CharactersToBeEscaped = @":/?&=;+!@#$()~',*";

// CharactersToLeaveUnescaped = @"[].";

NSString *encodedString = (NSString *)

CFBridgingRelease(CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault,

(CFStringRef)unencodedString,

NULL,

(CFStringRef)@"!*'();:@&=+$,/?%#[]",

kCFStringEncodingUTF8));

return encodedString;

}

、、、

、、、
//URLDEcode

-(NSString *)decodeString:(NSString*)encodedString

{

//NSString *decodedString = [encodedString stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding ];

NSString *decodedString  = (__bridge_transfer NSString *)CFURLCreateStringByReplacingPercentEscapesUsingEncoding(NULL,

(__bridge CFStringRef)encodedString,

CFSTR(""),

CFStringConvertNSStringEncodingToEncoding(NSUTF8StringEncoding));

return decodedString;

}
、、、

相关文章

网友评论

      本文标题:ios中URL字符串的URLencode与URLdecode

      本文链接:https://www.haomeiwen.com/subject/kprbmttx.html