質問編集履歴

2

コードを変更した

2019/01/11 06:05

投稿

thatnaoki
thatnaoki

スコア32

test CHANGED
File without changes
test CHANGED
@@ -206,9 +206,9 @@
206
206
 
207
207
  if response.result.isSuccess {
208
208
 
209
- let jsonData : JSON = JSON(response.result.value!)
209
+ let data = response.result.value!
210
-
210
+
211
- let articleList = try! JSONDecoder().decode(ArticlesListResult.self, from: jsonData)
211
+ let articleList = try! JSONDecoder().decode(ArticlesListResult.self, from: data as! Data)
212
212
 
213
213
  } else {
214
214
 
@@ -226,15 +226,13 @@
226
226
 
227
227
  上記コードですと、
228
228
 
229
- ```Swift
230
-
231
- let articleList = try! JSONDecoder().decode(ArticlesListResult.self, from: jsonData)
232
-
233
- ```
229
+ ```
234
-
235
-
236
-
230
+
237
- の部分で、Cannot convert value of type 'JSON' to expected argument type 'Data'というfatal errorが出てしまいます。
231
+ Could not cast value of type '__NSDictionaryI' (0x10326ca98) to 'NSData' (0x10326b580).
232
+
233
+ ```
234
+
235
+ というエラーが出てしまいます。
238
236
 
239
237
 
240
238
 

1

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

2019/01/11 06:05

投稿

thatnaoki
thatnaoki

スコア32

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