macosswift4.1

Getting error "data corrupted" while parsing json in swift 4 for Mac OS Application


I am getting an error in json parsing can anyone help me to solve the error.

My json data:

{
"message": "Batch found.",
"batch": {
    "batchID": "BA000000001",
    "name": "JUN-2014",
    "code": "TBATCH",
    "status": 1,
    "coordinatorName": null,
    "startDate": "2016-04-01T00:00:00",
    "endDate": "2020-04-01T00:00:00",
    "createdBy": "LU000000019",
    "createdOn": "2016-04-01T00:00:00",
    "updatedBy": "LU000000019",
    "updatedOn": "2018-10-11T11:51:46",
    "schoolID": "BS00001"
}

}

my code: Code Picture


Solution

  • Please read the error message and your code, the error is pretty clear:

    It's just a typo: Data vs. Date

    Both startDate and endDate are Date.

    And you can delete the date formatter if you set the date decoding strategy to .iso8601