MVVM_Swift
MVVM_Swift copied to clipboard
app crash due to invalid json
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)
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"
}
}
Hi @shravanteegala,
Please check my PR. I have resolved it.
Thanks