Hi guys,
I have a problem with the milestone, as the data made by myself in a custom .json file is parsed successfully, but without being shown in the table view.
I put the file in the bundle, then I parsed it:
let filePath = Bundle.main.url(forResource: "Towns", withExtension: "json")
if let url = filePath {
if let data = try? Data(contentsOf: url) {
parse(json: data)
print("data parsed")
return
} else {
print("error")
}
} else {
print("error")
}
So, when I load the table view, I get "data parsed" message, but that's all, no data in the table view at all. It's worth noting that in parse() function I also included reloading the table view.
Now I think it might be the way I wrote the .json file, as I have no experience in doing it whatsoever. I wrote it like this:
[
{
"town": "x",
"info": "y",
"worth it": "z"
},
{
"town": "x",
"info": "y",
"worth it": "z"
},
{
"town": "x",
"info": "y",
"worth it": "z"
},
{
"town": "x",
"info": "y",
"worth it": "z"
},
{
"town": "x",
"info": "y",
"worth it": "z"
},
{
"town": "x",
"info": "y",
"worth it": "z"
}
]
Could the problem be my .json formatting? If yes, why the hell Xcode tells me that the data has been parsed succesfully?