質問編集履歴
3
誤字修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -92,7 +92,7 @@
|
|
92
92
|
|
93
93
|
let statusCode: Int
|
94
94
|
|
95
|
-
let body: MemoModel
|
95
|
+
let body: [MemoModel]
|
96
96
|
|
97
97
|
|
98
98
|
|
2
swift側のコードを追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -85,3 +85,59 @@
|
|
85
85
|
|
86
86
|
|
87
87
|
Swiftでは期待しているjsonのみしかdecodeできなかった。
|
88
|
+
|
89
|
+
```
|
90
|
+
|
91
|
+
struct res: Decodable {
|
92
|
+
|
93
|
+
let statusCode: Int
|
94
|
+
|
95
|
+
let body: MemoModel
|
96
|
+
|
97
|
+
|
98
|
+
|
99
|
+
struct MemoModel: Decodable {
|
100
|
+
|
101
|
+
var id: Int
|
102
|
+
|
103
|
+
var name: String
|
104
|
+
|
105
|
+
var date: Date
|
106
|
+
|
107
|
+
}
|
108
|
+
|
109
|
+
}
|
110
|
+
|
111
|
+
func jsonDecode(data: Data) {
|
112
|
+
|
113
|
+
let decoder: JSONDecoder = JSONDecoder()
|
114
|
+
|
115
|
+
decoder.dateDecodingStrategy = .formatted(.iso8601Shrt)
|
116
|
+
|
117
|
+
let decodedRes = try! decoder.decode(res.self, from: data)
|
118
|
+
|
119
|
+
print(decodedRes)
|
120
|
+
|
121
|
+
}
|
122
|
+
|
123
|
+
extension DateFormatter {
|
124
|
+
|
125
|
+
static let iso8601Shrt: DateFormatter = {
|
126
|
+
|
127
|
+
let formatter = DateFormatter()
|
128
|
+
|
129
|
+
formatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss"
|
130
|
+
|
131
|
+
formatter.calendar = Calendar(identifier: .iso8601)
|
132
|
+
|
133
|
+
formatter.timeZone = TimeZone(secondsFromGMT: 0)
|
134
|
+
|
135
|
+
formatter.locale = Locale(identifier: "en_US_POSIX")
|
136
|
+
|
137
|
+
return formatter
|
138
|
+
|
139
|
+
}()
|
140
|
+
|
141
|
+
}
|
142
|
+
|
143
|
+
```
|
1
期待しているjsonに句読点を加筆しました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -16,9 +16,9 @@
|
|
16
16
|
|
17
17
|
{
|
18
18
|
|
19
|
-
|
19
|
+
"statusCode": 200,
|
20
20
|
|
21
|
-
|
21
|
+
"body": [{\"id\": 1, \"name\": \"sample1\", \"date\": \"2021-10-25T10:58:00\"},{\"id\": 2, \"name\": \"sample1\", \"date\": \"2021-10-25T10:58:00\"}]
|
22
22
|
|
23
23
|
}
|
24
24
|
|
@@ -36,11 +36,11 @@
|
|
36
36
|
|
37
37
|
{
|
38
38
|
|
39
|
-
|
39
|
+
"statusCode": 200,
|
40
40
|
|
41
|
-
|
41
|
+
"body": "[{\"id\": 1, \"name\": \"sample1\", \"date\": \"2021-10-25T10:58:00\"},{\"id\": 2, \"name\": \"sample1\", \"date\": \"2021-10-25T10:58:00\"}]"
|
42
42
|
|
43
|
-
}
|
43
|
+
}
|
44
44
|
|
45
45
|
```
|
46
46
|
|
@@ -80,8 +80,6 @@
|
|
80
80
|
|
81
81
|
|
82
82
|
|
83
|
-
|
84
|
-
|
85
83
|
### 補足情報(FW/ツールのバージョンなど)
|
86
84
|
|
87
85
|
|