使用stringByAddingPercentEncodingWithAllowedCharacters轉(zhuǎn)換一下就好了
[objc] view plain copy
NSString * str = @"https://www.baidu.com/s?wd=你好";
NSURL * url = [NSURL URLWithString:[str stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLFragmentAllowedCharacterSet]]];