ในกรณีที่อีกรายละเอียด:
ฉันพยายามที่จะเข้าถึงระดับจากการรูปแบบ api(เชื่อมโยงด้านล่างนี้)ที่มีอยู่ในมันเป็นโครงสร้างเป็นเบอร์อยู่ที่จุดเริ่มต้นหนึ่งในระดับ(25th_percentile). ฉันไม่สามารถสร้างเป็นอย่างต่อเนื่องในรุ่นของฉันเพราะฉันไม่สามารถเริ่มการปล่อยให้คุณค่ากับเบอร์(ie,25 ใน 25th_percentile). ว่าคุณสามารถเข้าถึงข้อมูลที่ถนน 25 ตัระดับร้อยละ?
ของรหัสคือที่ตามมา ตอนที่ฉันใช้ enum ที่แนะนำให้ฉันเป็น"ไม่เหมือนกัจะ decodable โพรโทคอล"ข้อผิดพลาด
//
// 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"
}