這個連結中%形式的引數轉換成中文
我們需要使用如下的方法
NSString *string_1 = [@"https://www.baidu.com/baidu?tn=monline_3_dg&ie=utf-8&wd=%E6%88%91%E4%BB%AC"
stringByRemovingPercentEncoding];
NSLog(@"%@",string_1);
複製程式碼
#將連結中的中文轉換成%形式 方法一:
NSString *string_2 = [@"https://www.baidu.com/baidu?tn=monline_3_dg&ie=utf-8&wd=我們"
stringByAddingPercentEncodingWithAllowedCharacters:
[NSCharacterSet characterSetWithCharactersInString:@"我們"].invertedSet];
NSLog(@"%@",string_2);
複製程式碼
方法二:
NSString *urlStr = @"http://api.douban.com/v2/movie/nowplaying?app_name=doubanmovie&client=e:iPhone4,1|y:iPhoneOS_6.1|s:mobile|f:doubanmovie_2|v:3.3.1|m:PP_market|udid:aa1b815b8a4d1e961347304e74b9f9593d95e1c5&alt=json&version=2&start=0&city=北京&apikey=0df993c66c0c636e29ecbb5344252a4a";
NSString *urlEncode = [urlStr stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
複製程式碼