Fornire ulteriori dettagli:
Sto cercando di accedere a un livello da un'API (link qui sotto) che ha nella sua struttura, un numero all'inizio di uno dei livelli (25th_percentile). Io sono in grado di creare una costante nel mio modello, perché non riesco a far partire il lasciate che il valore con un numero (cioè 25 in 25th_percentile). Come si può accedere ai dati al 25 ° percentile livello?
Il mio codice è il seguente. Quando uso enum come suggerito, ho un "non conforme a decodificabile protocollo di errore".
//
// SchoolData.swift
//
//
import Foundation
struct Results: Decodable {
let results: [SelectedSchool]
}
struct SelectedSchool: Decodable, Identifiable {
let id: Int
let fed_sch_cd: String
let latest: LatestData
}
struct LatestData: Decodable {
let school: SchoolDetails
let admissions: AdmissionsDetails
}
struct SchoolDetails: Decodable {
let name: String
let school_url: String
}
struct AdmissionsDetails: Decodable {
let admission_rate: AdmissionRateDetails
let sat_scores: SATScores
}
struct SATScores: Decodable {
let midpoint: SATSubjects
let the25th_percentile: SATSubjects2
enum CodingKeys: String, CodingKey {
case the25th_percentile = "25th_percentile"
}
}
struct SATSubjects: Decodable {
let math: Int?
let writing: Int?
let critical_reading: Int?
}
struct SATSubjects2: Decodable {
let math: Int?
let writing: Int?
let critical_reading: Int?
}
struct AdmissionRateDetails: Decodable {
let overall: Float?
}
struct URLName {
let partialURL = "https://api.data.gov/ed/collegescorecard/v1/schools?school.name="
var searchTerm: String = ""
let apiKey = "&api_key=myapikey"
}