I have JSON Structure
for decoding Purpose i performed this
i get an error as
I tried giving an optional to subject still not working any idea how to deal with this type of JSON
Code Block [ { name: "Boo", title: "Hello Boo", value: [ subject: 88 ] }, { name: "Foo", title: "Hello Foo", } ]
for decoding Purpose i performed this
Code Block struct Students: Decodable { let name: String, let title: String, let value: ValueHeader } struct ValueHeader: Decodable { let subject: Int? }
Code Block fileprivate func fetchTaskItems(completion: @escaping (Result<[Students], Error>) -> ()) { guard let url = URL(string: jsonString) else { return } URLSession.shared.dataTask(with: url) { (data, response,err) in if let err = err { completion(.failure(err)) return } do { let taskItem = try JSONDecoder().decode([Students].self, from: data!) completion(.success(taskItem)) } catch let jsonError { completion(.failure(jsonError)) } }.resume() }
i get an error as
Code Block valueNotFound(Swift.KeyedDecodingContainer<App.ValueHeader.(unknown context at $10fd991dc).CodingKeys>,
I tried giving an optional to subject still not working any idea how to deal with this type of JSON