###前提・実現したいこと
swift3.1 Alamofireを使ってYahoo! APIから、戻り値を取得したい
###発生している問題・エラーメッセージ
戻り値が「nil」になってしまう
###該当のソースコード
swift
1import UIKit 2import Alamofire 3 4class ViewController: UIViewController { 5 6 @IBAction func connect(_ sender: UIButton) { 7 let url = "https://jlp.yahooapis.jp/FuriganaService/V1/furigana" 8 let appid = "my_appid" 9 let text = "隣の客はよく柿食う客だ" 10 11 let targetURL = url + "?appid=" + appid + "&sentence=" + text 12 13 // 日本語を含むのでエンコード 14 let encodeURL = targetURL.addingPercentEncoding(withAllowedCharacters: NSCharacterSet.urlQueryAllowed) 15 16 // リクエスト実行 17 Alamofire.request(encodeURL!).responseJSON { response in 18 // ↓ nilが出力される 19 print(response.result.value) 20 } 21 22 } 23 override func viewDidLoad() { 24 super.viewDidLoad() 25 // Do any additional setup after loading the view, typically from a nib. 26 } 27 override func didReceiveMemoryWarning() { 28 super.didReceiveMemoryWarning() 29 // Dispose of any resources that can be recreated. 30 } 31}
###試したこと
・ATSの無効化
###補足情報(言語/FW/ツール等のバージョンなど)
swift3.1
Xcode8.3.3
macOS Sierra 10.12.5
初投稿につき、不備がありましたらご容赦ください。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/06/14 07:52 編集
2017/06/14 07:51