You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
"Expected to find value of type Dictionary<String, Any>, but value was missing at [0]/address",
1232
+
decoding:[Person].self,
1233
+
fromJSON:#"""
1234
+
[
1235
+
{
1236
+
"first_name": "John",
1237
+
"last_name": "Appleseed",
1238
+
"address": null
1239
+
}
1240
+
]
1241
+
"""#
1242
+
)
1243
+
}
1244
+
1245
+
func test_decodingError_keyNotFound(){
1246
+
expectErrorDescription(
1247
+
"Key not found: expected 'name' at [0]/address/city/birds/[1]",
1248
+
decoding:[Person].self,
1249
+
fromJSON:#"""
1250
+
[
1251
+
{
1252
+
"first_name": "John",
1253
+
"last_name": "Appleseed",
1254
+
"address": {
1255
+
"street": "123 Main St",
1256
+
"city": {
1257
+
"name": "Cupertino",
1258
+
"birds": [
1259
+
{
1260
+
"name": "The Big One",
1261
+
"feathers": "all"
1262
+
},
1263
+
{
1264
+
"feathers": "some"
1265
+
}
1266
+
]
1267
+
}
1268
+
}
1269
+
}
1270
+
]
1271
+
"""#
1272
+
)
1273
+
}
1274
+
1275
+
func test_decodingError_dataCorrupted(){
1276
+
expectErrorDescription(
1277
+
#"""
1278
+
Data corrupted: The given data was not valid JSON. Underlying error: Error Domain=NSCocoaErrorDomain Code=3840 "Unexpected character 'a' around line 5, column 10." UserInfo={NSJSONSerializationErrorIndex=81, NSDebugDescription=Unexpected character 'a' around line 5, column 10.}
1279
+
"""#,
1280
+
decoding:[Person].self,
1281
+
fromJSON:#"""
1282
+
[
1283
+
{
1284
+
"first_name": "John",
1285
+
"last_name": "Appleseed",
1286
+
address
1287
+
}
1288
+
]
1289
+
"""#
1290
+
)
1291
+
}
1103
1292
}
1104
1293
1105
1294
// MARK: - Helper Types
@@ -1130,6 +1319,35 @@ struct TopLevelWrapper<T> : Codable, Equatable where T : Codable, T : Equatable
1130
1319
}
1131
1320
}
1132
1321
1322
+
structPerson:Decodable{
1323
+
varfirstName,lastName:String
1324
+
varaddress:Address
1325
+
}
1326
+
1327
+
structAddress:Decodable{
1328
+
varstreet:String
1329
+
varcity:City
1330
+
}
1331
+
1332
+
structCity:Decodable{
1333
+
varname:String
1334
+
varbirds:[Bird]
1335
+
}
1336
+
1337
+
structBird:Decodable{
1338
+
varname,feathers:String
1339
+
}
1340
+
1341
+
/// A struct whose encoded representation has string keys that consist only of numbers.
0 commit comments