iOS 开发中,经常需要对url编码与解码。 iOS9之前 1.url编码 1 2 3 4 5 6 7 8 9 10 11 12 + (NSString*)encodeUrl:(NSString *)urlString { if (0 == urlString.length) { return KBlankString; } return (__bridge_transfer NSString*) CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault, (CFStringRef)urlString, NULL, (CFStringRef)@"!*'();:@&=+$,/?%#[]", kCFStringEncodingUTF8); } 2.url