ios 如何创建响应类?

qxgroojn  于 2023-06-25  发布在  iOS
关注(0)|答案(1)|浏览(89)

虽然我有两个JSON响应类,但结构会抛出一个错误。请告诉我如何处理此iOS SWIFT问题。

// MARK: - Welcome
struct OTPRes: Codable {
    let response: Response
}

// MARK: - Response
struct Response: Codable {
    let success: String
    let result: Result
}

// MARK: - Result
struct Result: Codable {
    let encryptedOtp: String
}
// Second JSON 

// MARK: - Welcome
struct LoginRes: Codable {
    let response: Response
}

// MARK: - Response
struct Response: Codable {
    let success: String
    let result: Result
}

// MARK: - Result
struct Result: Codable {
    let lastName: String
    let deviceIDS: [DeviceID]
    let loginID: String
    let profileImage: String
    let platform: String
    let doNotDisturb: Bool
    let segment, email: String
    let editAccess, roaming: Bool
    let contactID, mobile, accountclass: String
    let dashboardInfo: DashboardInfo
    let assignedUserID, accountNumber, userName, accessToken: String
    let lastLoginTime, accountID, firstName, servicetype: String
    let pushNotifications: Bool
    let response, success, basePlan, location: String

    enum CodingKeys: String, CodingKey {
        case lastName
        case deviceIDS = "deviceIds"
        case loginID = "loginId"
        case profileImage, platform, doNotDisturb, segment, email, editAccess, roaming
        case contactID = "contactId"
        case mobile, accountclass, dashboardInfo
        case assignedUserID = "assigned_user_id"
        case accountNumber, userName, accessToken, lastLoginTime
        case accountID = "accountId"
        case firstName, servicetype, pushNotifications, response, success, basePlan, location
    }
}

// MARK: - DashboardInfo
struct DashboardInfo: Codable {
    let noOfServiceAccounts: String
}

// MARK: - DeviceID
struct DeviceID: Codable {
    let accountName, accountNo, deviceID, email: String

    enum CodingKeys: String, CodingKey {
        case accountName, accountNo
        case deviceID = "deviceId"
        case email
    }
}

无法创建JSON响应,请帮助我。

//First JSON

{
    "response": {
        "success": "true",
        "result": {
            "lastName": "المغدوي",
            "deviceIds": [
                {
                    "accountName": "234234567",
                    "accountNo": "SA1223644",
                    "deviceId": "967101905541",
                    "email": "126@gmail.com"
                }
            ],
            "loginId": "967101905541",
            "profileImage": "http://182.18.131.165:8282/storage/2023/June/week4/1238788_6494669a4d847.png",
            "platform": "Prepaid",
            "doNotDisturb": false,
            "segment": "",
            "email": "126@gmail.com",
            "editAccess": true,
            "roaming": true,
            "contactId": "12x1223301",
            "mobile": "980678910",
            "accountclass": "Service",
            "dashboardInfo": {
                "noOfServiceAccounts": "1"
            },
            "assigned_user_id": "19x1",
            "accountNumber": "SA1223644",
            "userName": "967101905541",
            "accessToken": "eyJhbGciOiJIUzUxMiJ9.eyJ0ZW5hbnRUeXBlIjoiY2xpZW50IiwidGVuYW5jeUlkIjoiTVZOT19XRUJfUFRDIiwibG9naW5Vc2VybmFtZSI6Ijk2NzEwMTkwNTU0MSIsImxvZ2luVHlwZSI6ImRldmljZUlkIiwiYXBwSWQiOiIyYWYyMzI3Mi1hZTNjLTM3ODItYWIwYS0xOTdlMzcyZWQ4NzkiLCJhY2NvdW50Tm8iOiJTQTEyMjM2NDQiLCJ0b2tlblR5cGUiOiJ1c2VyVG9rZW4iLCJleHAiOjE2ODc1MzA5NjgsImlhdCI6MTY4NzQ4Nzc2OCwiZW1haWwiOiJtb2JpbGVhcHAxMjNAeW9wbWFpbC5jb20ifQ.DuCIf06KCw0MmoRJYihapDGSKjjJT_ROWub8whqVabvtT3ygA7rEDF0s7XpU15hA0tocLAbNAePBPfx4qYA11w",
            "lastLoginTime": "2023-06-22 20:48:25",
            "accountId": "11x1223644",
            "firstName": " أناهيد",
            "servicetype": "VoLTE",
            "pushNotifications": false,
            "response": "User logged in correctly",
            "success": "true",
            "basePlan": "4G 130",
            "location": ""
        }
    }
}
//Second JSON 

{
    "response": {
        "success": "true",
        "result": {
            "encryptedOtp": "f874b06c8c728145a0cf2b9f78356b42c0eb9a99c33cb988516de548738bd971"
        }
    }
}
kkih6yb8

kkih6yb81#

// MARK: - Result
struct Result: Codable {
    let lastName: String
    let deviceIDS: [DeviceID]
    let loginID: String
    let profileImage: String
    let platform: String
    let doNotDisturb: Bool
    let segment, email: String
    let editAccess, roaming: Bool
    let contactID, mobile, accountclass: String
    let dashboardInfo: DashboardInfo
    let assignedUserID, accountNumber, userName, accessToken: String
    let lastLoginTime, accountID, firstName, servicetype: String
    let pushNotifications: Bool
    let response, success, basePlan, location: String

    enum CodingKeys: String, CodingKey {
        case lastName
        case deviceIDS = "deviceIds"
        case loginID = "loginId"
        case profileImage, platform, doNotDisturb, segment, email, editAccess, roaming
        case contactID = "contactId"
        case mobile, accountclass, dashboardInfo
        case assignedUserID = "assigned_user_id"
        case accountNumber, userName, accessToken, lastLoginTime
        case accountID = "accountId"
        case firstName, servicetype, pushNotifications, response, success, basePlan, location
    }
}

// MARK: - Response
struct Response: Codable {
    let success: String
    let result: Result
}

// MARK: - Welcome
struct LoginRes: Codable {
    let response: Response
}

我想你需要改变这样的顺序。

相关问题