Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Alamofire returns wrong encoding

I`m using

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

to make get-request. Response contains сyrillic symbols and in responseString they looks like this (top-right):

top right

How should I fix encoding?

like image 629
SwiftStudier Avatar asked Jul 30 '15 20:07

SwiftStudier


2 Answers

You can use NSUTF8StringEncoding with Alamofire's 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},title{Продукция Apple}

like image 103
Eric Aya Avatar answered Nov 19 '22 08:11

Eric Aya


Now, you have to use responseString(encoding: String.Encoding.utf8) instead

like image 36
KOMETSOFT SL Avatar answered Nov 19 '22 08:11

KOMETSOFT SL