Encoding IOS:ASIHTTPRequest和accents

Encoding IOS:ASIHTTPRequest和accents,encoding,asihttprequest,nsurl,Encoding,Asihttprequest,Nsurl,我向PHP/Mysql服务器发送请求,如下所示: NSURL *url = [NSURL URLWithString:@"http://xxx/webservice.php5/"]; ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url]; [request setPostValue:[self.searchBar text] forKey:@"libelle"]; [request setResponseEnc

我向PHP/Mysql服务器发送请求,如下所示:

NSURL *url = [NSURL URLWithString:@"http://xxx/webservice.php5/"];
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
[request setPostValue:[self.searchBar text] forKey:@"libelle"];
[request setResponseEncoding:NSUTF8StringEncoding];
[request setDefaultResponseEncoding:NSUTF8StringEncoding];
[request setDelegate:self];
[request startAsynchronous];
我的回答是这样的:

    NSString *responseString =   [request responseString] ;
这里,responseString值应该是“pyré”,但我得到:pyr\u7800。 Mysql/PHP服务器的编码设置为:

字符集客户端utf8字符集连接utf8 字符集数据库拉丁1字符集文件系统二进制 字符集结果utf8字符集1 字符集系统utf8 字符集\u dir/usr/mysql/share/mysql/charsets/

您是否知道如何获得正确的字符而不是\u7800


提前谢谢。

问题可能出在Mysql/PHP服务器上

您的responseString以Unicode格式返回

您应该更改配置服务器,但是另一个解决方案应该是在得到响应时将其转换为UTF8

试试看:

NSString *responseString = [request responseString];
[NSString stringWithString:[responseString cStringUsingEncoding:NSUnicodeStringEncoding] encoding:NSUTF8StringEncoding];
看看这篇文章: