JSON decoder shows empty list however everything is coded properly. I get a json array from the server, in Xcode console it still shows an empty array.
News(news: [])
Whiel current response from a server is a valid json array:
{"news":[{"info_id":"unique id","title":"some title","description":"some description","date":"2019-07-10","time":"10:23:00"}]}
My struct to parse json is:
struct News: Codable {
let news = [Info]()
struct Info: Codable {
let infoId: String
let title: String
let description: String
let date: String
let time: String
private enum CodingKeys: String, CodingKey {
case infoId = "info_id"
}
}
}
I try to decode that array of posts with that code:
let decoder = JSONDecoder()
let news: News = try decoder.decode(News.self, from: data)
print("\(news)")
SOLUTION: let news = [Info]() changed to var news = [Info]()