IOS把url中含有的中文字符转化为UTF8编码方法

时间:2020-11-29 07:46:59
//预留参数的网址 NSString *baseUrlString = @"http://lolbox.duowan.com/phone/apiCheckUser.php?action=getPlayersInfo&serverName=%@&target=%@";
NSString *paramServer = @"电信十四"
NSString *paramName = @"蛋壳儿"; //合成新的网址 
NSString *urlString = [NSString stringWithFormat:baseUrlString,paramServer,paramName]; //将网址转化为UTF8编码 
NSString *urlStringUTF8 = [urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];