NSString *str = CFBridgingRelease(CFURLCreateStringByAddingPercentEscapes(NULL, (__bridge CFStringRef)someStringToEncode, NULL, (__bridge CFStringRef)@"!*'"();:@&=+$,/?%#[]% ", CFStringConvertNSStringEncodingToEncoding(NSUTF8StringEncoding)));
对应的javascript 代码
var str = encodeURIComponent(str);
OC函数:
+(NSString*)encodeURIComponent:(NSString*)str{ return CFBridgingRelease(CFURLCreateStringByAddingPercentEscapes(NULL, (__bridge CFStringRef)str, NULL, (__bridge CFStringRef)@"!*'"();:@&=+$,/?%#[]% ", CFStringConvertNSStringEncodingToEncoding(NSUTF8StringEncoding))); }
欢迎各位指正