//swift
let customAllowedSet = NSCharacterSet(charactersIn:"!*'();:@&=+$,/?%#[]").inverted
let infoValue = str.addingPercentEncoding(withAllowedCharacters: customAllowedSet)!
//oc
NSString *encodedString = (NSString *)CFURLCreateStringByAddingPercentEscapes(
NULL,
(CFStringRef)unencodedString,
NULL,
(CFStringRef)@"!*'();:@&=+$,/?%#[]",
kCFStringEncodingUTF8 );
本文介绍如何使用Swift和Objective-C进行URL编码,确保特殊字符在网络传输中正确解析。通过自定义允许集,实现对指定字符的百分比编码。
1737

被折叠的 条评论
为什么被折叠?



