MVVM_Swift icon indicating copy to clipboard operation
MVVM_Swift copied to clipboard

app crash due to invalid json

Open shravanteegala opened this issue 4 years ago • 2 comments

Fatal error: 'try!' expression unexpectedly raised an error: Swift.DecodingError.dataCorrupted(Swift.DecodingError.Context(codingPath: [], debugDescription: "The given data was not valid JSON.", underlyingError: Optional(Error Domain=NSCocoaErrorDomain Code=3840 "Invalid value around character 0." UserInfo={NSDebugDescription=Invalid value around character 0.}))): file /Users/suramba/Downloads/MVVM_Swift-master/MVVM_New/WebService/APIService.swift, line 23 2021-02-07 07:30:05.669505+0530 MVVM_New[1583:52578] Fatal error: 'try!' expression unexpectedly raised an error: Swift.DecodingError.dataCorrupted(Swift.DecodingError.Context(codingPath: [], debugDescription: "The given data was not valid JSON.", underlyingError: Optional(Error Domain=NSCocoaErrorDomain Code=3840 "Invalid value around character 0." UserInfo={NSDebugDescription=Invalid value around character 0.}))): file /Users/suramba/Downloads/MVVM_Swift-master/MVVM_New/WebService/APIService.swift, line 23 (lldb)

shravanteegala avatar Feb 07 '21 02:02 shravanteegala

Change Employee.swift class to this:

import Foundation

// MARK: - Welcome
struct Employees: Decodable {
    let status: String
    let data: [EmployeeData]
}

// MARK: - Datum
struct EmployeeData: Decodable {
    let id: Int
    let employeeName: String
    let employeeSalary: Int
    let employeeAge: Int
    let profileImage: String

    enum CodingKeys: String, CodingKey {
        case id
        case employeeName = "employee_name"
        case employeeSalary = "employee_salary"
        case employeeAge = "employee_age"
        case profileImage = "profile_image"
    }
}

Odiljon1994 avatar Jun 08 '21 03:06 Odiljon1994

Hi @shravanteegala,

Please check my PR. I have resolved it.

Thanks

Ilesh avatar Feb 20 '22 17:02 Ilesh