我的GitHub
0%

iOS encode

相信大家总会碰到需要encode的时候,接着百度啊,然后发现stringByAddingPercentEscapesUsingEncoding这个方法,但是这个方法有时候无法对+等符号进行encode。那这时候咋办呢?

img

img

//encode

CF_EXPORT

CFStringRef CFURLCreateStringByAddingPercentEscapes(CFAllocatorRef allocator, CFStringRef originalString, CFStringRef charactersToLeaveUnescaped, CFStringRef legalURLCharactersToBeEscaped, CFStringEncoding encoding);

NSString encodedValue = (NSString)CFBridgingRelease(CFURLCreateStringByAddingPercentEscapes(nil,(CFStringRef)value, nil,(CFStringRef)@”!*’();:@&=+$,/ %#[]”, kCFStringEncodingUTF8));