Hi @Claude31,
Thank you for the response! After redoing the naming conventions and creating the coding keys, the first problem was my URL request, which then once I fixed (and validated by printing the response) I then couldn't seem to get the response to parse into the individual "ValueData" elements...
func getMember (completion: @escaping(Result<[ValueData], WasatchError>) -> Void){
let task = URLSession.shared.dataTask(with: resourceRequest) {(data, response, error) in
guard let jsonData = data else {
completion(.failure(.noData))
return }
do {
let wasatchResponse = try JSONDecoder().decode(WasatchResponse.self, from: jsonData)
let values = wasatchResponse.value
completion(.success(values))
}catch{
completion(.failure(.cannotProcessData))
}
print(String(data: jsonData, encoding: .utf8)!)
}
task.resume()
}
What's interesting is that last print statement still shows me the JSON structure I'm looking for, however for some reason I'm still throwing the "completion(.failure(.cannotProcessData))" statement.
Could having non-matching data types make the JSON parsing fail? (i.e. my struct defining a string when the JSON response is a bool?)
Topic:
Programming Languages
SubTopic:
Swift
Tags: