Alamofire returns incorrect encoding

I use

Alamofire.request(.GET, "http://") .responseString { _, _, string, _ in println(string) } 

to make a request for receipt. The response contains Cyrillic characters, and in responseString they look like this (top right):

top right

How do I fix the encoding?

+4
source share
2 answers

You can use NSUTF8StringEncoding using the Alamofire responseString method:

 Alamofire.request(.GET, "http://my1test.ru/applejesus.php?task=getCategory&categoryNumber=1") .responseString(encoding: NSUTF8StringEncoding) { (request, response, string, error) -> Void in if let result = string { println(result) } } 

Result:

picture { http://ipic.su/img/img7/fs/ProdukciyaApple.1438079721.png }, name {Apple Products}

+3
source

Now you should use responseString(encoding: String.Encoding.utf8) instead

0
source

All Articles