其实很简单,只需要对中文进行UTF-8转一下就可以了。代码如下
NSString *urlString = @"请求的URL地址";
// url包含中文的处理
NSString *chineseUTF8 = [cityName stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet characterSetWithCharactersInString:cityName]];
// NSString *chineseUTF8 = [cityName stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];// 该方法已过期
// 拼接参数 注意:stringByAppendingUrlComponent:是我自己封装的方法
urlString = [urlString stringByAppendingUrlComponent:[NSString stringWithFormat:@"%@", chineseUTF8]];
// 发送get请求
[[AFHTTPSessionManager manager] GET:xxx 略......