koher
import Foundation let json = """ [ { "id": 1, "solde": { "id": 1 } }, { "id": 2, "solde": { "id": 2 } }, { "id": 3, "solde": { "id": 3 } } ] """ struct Utilisateur: Codable { let id: Int let solde: [Solde] } struct Solde: Codable { let id: Int } let jsonData = json.data(using: .utf8)! let decoded = try! JSONDecoder().decode([Utilisateur].self, from: jsonData) print(decoded)
Fatal error: 'try!' expression unexpectedly raised an error: Swift.DecodingError.typeMismatch(Swift.Array<Any>, Swift.DecodingError.Context(codingPath: [_JSONKey(stringValue: "Index 0", intValue: 0), CodingKeys(stringValue: "solde", intValue: nil)], debugDescription: "Expected to decode Array<Any> but found a dictionary instead.", underlyingError: nil)): file /home/buildnode/jenkins/workspace/oss-swift-4.1-package-linux-ubuntu-16_04/swift/stdlib/public/core/ErrorType.swift, line 184 Current stack trace: 0 libswiftCore.so 0x00007f2b8b1475c0 _swift_stdlib_reportFatalErrorInFile + 221 1 libswiftCore.so 0x00007f2b8aeb63dc <unavailable> + 1369052 2 libswiftCore.so 0x00007f2b8b0f0222 <unavailable> + 3703330 3 libswiftCore.so 0x00007f2b8b0f1689 <unavailable> + 3708553 4 libswiftCore.so 0x00007f2b8aeb5ad6 <unavailable> + 1366742 ...