包含中文字符的NSString转换为NSURL结果为nil解决方法

使用stringByAddingPercentEncodingWithAllowedCharacters转换一下就好了


NSString * str = @"https://www.baidu.com/s?wd=你好";
NSURL * url = [NSURL URLWithString:[str stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLFragmentAllowedCharacterSet]]];


你可能感兴趣的:(ios,Objective-C,NSString,NSURL)