Я бы посоветовал Codable protocol
let json = "{\"isOk\":true,\"result\":[{\"Name\":\"file0\",\"Size\":93316,\"MimeType\":\"image/jpeg\",\"Body\":\"/9j/4QAYRXIDIwMTAvM...\"},{\"Name\":\"file1\",\"Size\":146597,\"MimeType\":\"image/jpeg\",\"Body\":\"/9j/4AAQSkZJRgABAgAAA..\"}],\"errorMessage\":null}"
let data = json.data(using: .utf8)!
struct APIResponse: Decodable {
let isOk: Bool
let result: [Item]
let errorMessage: String?
struct Item: Decodable {
let name: String
let size: Double
let mimeType: String
let body: String
enum CodingKeys: String, CodingKey {
case name = "Name"
case size = "Size"
case mimeType = "MimeType"
case body = "Body"
}
}
}
let response = try! JSONDecoder().decode(APIResponse.self, from: data)
print(response)
// Output:
// APIResponse(isOk: true, result: [__lldb_expr_33.APIResponse.Item(name: "file0", size: 93316.0, mimeType: "image/jpeg", body: "/9j/4QAYRXIDIwMTAvM..."), __lldb_expr_33.APIResponse.Item(name: "file1", size: 146597.0, mimeType: "image/jpeg", body: "/9j/4AAQSkZJRgABAgAAA..")], errorMessage: nil)