字符串编码:
- (NSString *)urlEncode:(NSString *)oldString{ CFStringRef escaped = CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault, (__bridge CFStringRef)oldString, NULL, (CFStringRef)@"!*'();:@&=+$,/?%#[]", kCFStringEncodingUTF8); return [NSString stringWithFormat:@"%@", escaped]; }
字符串解码:
- (NSString *)urlDecode:(NSString *)oldString{ NSMutableString *unescaped = [NSMutableString stringWithString:oldString]; [unescaped replaceOccurrencesOfString:@"+" withString:@" " options:NSLiteralSearch range:NSMakeRange(0, [unescaped length])]; return [unescaped stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; }