Reputation: 97
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
Reputation: 894
Swift 3
let newStr = String(utf8String: stringToDecode.cString(using: .utf8)!)
Upvotes: 8