I get this error:
"typeMismatch(Swift.Dictionary<Swift.String, Any>, Swift.DecodingError.Context(codingPath: [], debugDescription: "Expected to decode Dictionary<String, Any> but found an array instead.", underlyingError: nil))"
In swift while decoding JSON (from django rest framework).
This is the json:
[
{
"id": 1,
"title": "1e todo",
"description": "1e todo test"
},
{
"id": 2,
"title": "2e todo",
"description": "2e todo test"
}
]
This is the parse function in Swift:
func parseJSON(todoData:Data){
let decoder = JSONDecoder()
do{
let decodedData = try decoder.decode(ToDoData.self, from: todoData)
fetchedTitle = decodedData.todoitems[1].title
print(fetchedTitle)
And the Structs in Swift:
import Foundation
struct ToDoData: Decodable {
//return een list met ToDoData
let todoitems: [Items]
}
struct Items: Decodable {
//return een list met ToDoData
let id: String
let title: String
let description: String
}
So its saying found an Array, but how can i get to the "Title" in the JSON file.