2017-08-21 16 views
0

Alamofireが私のサーバにutf-8パラメータを送信するようにするために、私は今は英語の文字を通常は送信しますが、ロシアの文字は象形文字として送信する必要があります。エンコードをチェックした後、私はそれがmaccyrillic文字を使用していることがわかりました。変換文字列をutf-8に変換するにはどうすればよいですか? (Swift、Alamofire)

LETパラメータ:パラメータ= [ "ユーザー名":login.text! "パスワード":!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"]! 
        } 
       } 

      } 

     } 

あなたの助けを必要としています。ありがとうございます。

+0

のvar strUtf8:ContiguousArray = "ここにあなたの文字列" あなたは非常にmutch – Torongo

答えて

2

スウィフト3

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

Source StackOverFlow

+0

感謝を.utf8CString! – Wolfak

+0

快楽:) ..うれしい私は助けた –

関連する問題