Wolfak
Wolfak

Reputation: 97

How convert string to utf-8? (Swift, Alamofire)

Me need so that Alamofire send utf-8 parameters to my server, now he transmits English characters normally, but Russian characters as hieroglyphs. After checking the encoding I found that it is used maccyrillic characters.

let parameters: Parameters = ["username": login.text!, "password": password.text!]

        Alamofire.request("link ti site", method: .post, parameters: parameters).responseJSON { response in

            switch response.result {
            case .success:

                let json = JSON(response.result.value)

            case .failure( _):

                var errorString = "NULL"

                if let data = response.data {
                    if let json = try? JSONSerialization.jsonObject(with: data, options: []) as! [String: String] {
                        errorString = json["error"]!
                    }
                }

            }

        }

Need your help. Thanks you.

Upvotes: 2

Views: 12872

Answers (1)

Abdul Waheed
Abdul Waheed

Reputation: 894

Swift 3

let newStr = String(utf8String: stringToDecode.cString(using: .utf8)!)

Source StackOverFlow

Upvotes: 8

Related Questions