I'm trying to load local JSON
file and parse using model which conforms to Decodable
protocol.
JSON file:
[
{
"body": {},
"header": {
"returnCode": "200",
"returnMessage": "Successfully Received",
}
}
]
Response Message model:
struct ResponseMessage: Decodable {
struct header: Decodable {
let returnCode: String
let returnMessage: String
}
}
Mock API implementation:
let url = Bundle.main.url(forResource: "MockJSONData", withExtension: "json")!
do {
let data = try Data(contentsOf: url)
let teams = try JSONDecoder().decode(ResponseMessage.self, from: data)
print(teams)
} catch {
print(error)
}
But Response Message returns empty data for that.
Appreciate your help and suggestions!
Thanks