Im trying to parse data with JSONDecoder, however I keep getting an error. I am unsure why? If anyone could have a look at the code and explain whats going wrong, it would be greatly appreciated!
struct Stops1 : Decodable{
let StopName : String
let StopLat : String
let StopLon: String
}
let path = Bundle.main.path(forResource: "newStops", ofType: "json")
let url = URL(fileURLWithPath: path!)
do {
let data = try Data(contentsOf: url)
let Stops = try JSONDecoder().decode([Stops1].self, from: data)
print(Stops)
}
catch let jsonErr {
print("Error occured during Parsing", jsonErr)
}
below is the local json file called "newStops" :
{
"Stops1" : {
{
"StopName": "loc 1",
"StopLat": "-46.450364",
"StopLon": "169.659519"
},
{
"StopName": "loc 2",
"StopLat": "-45.898395",
"StopLon": "170.486386"
},
{
"StopName": "loc 3",
"StopLat": "-36.635997",
"StopLon": "174.747697"
},
}
}