Я обнаружил некоторую проблему, если вы JSON
, который связан с ”
во многих местах, и он должен быть "
, поэтому сначала исправьте это, а затем ваш JSON
будет:
{
"status": 200,
"message": "Success",
"country": [
{
"id": 1,
"master": "India",
"type": 2,
"active": 1
},
{
"id": 2,
"master": "US",
"type": 2,
"active": 1
}
],
"cost": 13764,
"data": [
{
"id": 1,
"user_id": 167,
"country": 1,
"card": 1,
"category": 4,
"title": "kms",
"description": "check",
"cost": 444,
"attachment": "sample.png",
"create_date": "2019-02-13T00:00:00.000Z",
"device_id": "1111",
"app_type": "Android",
"location": "USA",
"user": {
"firstname": "Mike",
"lastname": "P"
},
"app_trans_card": {
"card": "012"
},
"app_trans_master": {
"master": "Domain"
}
}
]
}
Теперь вы можете создать свой Codable
протокол с ЭТИМ сайтом и кодом, который будет выглядеть так:
struct Root: Codable {
let status: Int
let message: String
let country: [Country]
let cost: Double
let data: [Datum]
}
struct Country: Codable {
let id: Int
let master: String
let type, active: Int
}
struct Datum: Codable {
let id, userID, country, card: Int
let category: Int
let title, description: String
let cost: Double
let attachment, createDate, deviceID, appType: String
let location: String
let user: User
let appTransCard: AppTransCard
let appTransMaster: AppTransMaster
enum CodingKeys: String, CodingKey {
case id
case userID = "user_id"
case country, card, category, title, description, cost, attachment
case createDate = "create_date"
case deviceID = "device_id"
case appType = "app_type"
case location, user
case appTransCard = "app_trans_card"
case appTransMaster = "app_trans_master"
}
}
struct AppTransCard: Codable {
let card: String
}
struct AppTransMaster: Codable {
let master: String
}
struct User: Codable {
let firstname, lastname: String
}