質問するログイン新規登録

質問編集履歴

2

コードを変更した

2019/01/11 06:05

投稿

thatnaoki
thatnaoki

スコア32

title CHANGED
File without changes
body CHANGED
@@ -102,8 +102,8 @@
102
102
  Alamofire.request(urlForApi, method: .get)
103
103
  .responseJSON { response in
104
104
  if response.result.isSuccess {
105
- let jsonData : JSON = JSON(response.result.value!)
105
+ let data = response.result.value!
106
- let articleList = try! JSONDecoder().decode(ArticlesListResult.self, from: jsonData)
106
+ let articleList = try! JSONDecoder().decode(ArticlesListResult.self, from: data as! Data)
107
107
  } else {
108
108
  print("Error: (String(describing: response.result.error))")
109
109
  }
@@ -112,12 +112,11 @@
112
112
  ```
113
113
 
114
114
  上記コードですと、
115
- ```Swift
116
- let articleList = try! JSONDecoder().decode(ArticlesListResult.self, from: jsonData)
117
115
  ```
116
+ Could not cast value of type '__NSDictionaryI' (0x10326ca98) to 'NSData' (0x10326b580).
117
+ ```
118
+ というエラーが出てしまいます。
118
119
 
119
- の部分で、Cannot convert value of type 'JSON' to expected argument type 'Data'というfatal errorが出てしまいます。
120
-
121
120
  この場合、response.result.valueをData型に変換する必要があるのかなと思うのですが、その方法がわかりません。
122
121
 
123
122
  どなたかご教授いただけますと幸いです。

1

タイトルをわかりやすくしました

2019/01/11 06:05

投稿

thatnaoki
thatnaoki

スコア32

title CHANGED
@@ -1,1 +1,1 @@
1
- Alamofireで取得してきたJSON型のデータをCodableで構造体化したい
1
+ Alamofireで取得してきたJSON型のデータをCodableプロトコルを使ってdecodeしたい
body CHANGED
File without changes