iOS URL编解码

//url 编码
NSString *urlString = @"http://www.baidu.com/中国.jpg";
NSURL *url = [NSURL URLWithString:[urlString stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]]];
NSLog(@"%@",url.absoluteString);
//http://www.baidu.com/%E4%B8%AD%E5%9B%BD.jpg
        
//url 解码
NSString *encodeString = @"http://www.baidu.com/%E4%B8%AD%E5%9B%BD.jpg";
NSLog(@"%@",[encodeString stringByRemovingPercentEncoding]);
//http://www.baidu.com/中国.jpg

你可能感兴趣的:(iOS URL编解码)