如何解决如何为enom值添加变量?
我正在开发具有多个API的大型应用程序。其中一种API,由于某种原因,一种API的结构如下:
{
"KOMN" : [
{
"state" : string,"state_full" : string,"city" : string,"volume" : string,"airport_name" : string,"military" : string,"faa_ident" : string,"icao_ident" : string,"chart_seq" : string,"chart_code" : string,"chart_name" : string,"pdf_name" : string,"pdf_path" : string
},{
"state" : string,...
]
And so on..
整个外部词典包含一个根据用户查询而变化的键。我需要一种在enom编码键值中“ KOMN”值所在的位置插入变量的方法。有没有办法做到这一点?我尝试了各种字符串插值,但是得到了关于要求“文字”值的enom的错误。如果我可以用我创建的变量替换该值,则数据提取将成功。
这是我的co:
struct ChartData: Codable {
let dataPoints: [DataPoints]
enum CodingKeys: String,CodingKey {
case dataPoints = "KDAB"
}
}
struct DataPoints: Codable {
let state: String?
let stateFull: String?
let city: String?
let volume: String?
let airportName: String?
let military: String?
let faaIdent: String?
let icaoIdent: String?
let chartSeq,chartCode,chartName,pdfName: String?
let pdfPath: String?
enum CodingKeys: String,CodingKey {
case state
case stateFull = "state_full"
case city,volume
case airportName = "airport_name"
case military
case faaIdent = "faa_ident"
case icaoIdent = "icao_ident"
case chartSeq = "chart_seq"
case chartCode = "chart_code"
case chartName = "chart_name"
case pdfName = "pdf_name"
case pdfPath = "pdf_path"
}
}
据我了解,结构如下: 带有一个键“ KOMN”的字典(我需要替代它)>字典数组。我试过了 让importChart = chartData?.dataPoints 让importimportedListingPdf1 = importantChart?[0] .pdfPath 打印(importedListingPdf1)
but got nil when I tried removing the keycoding = hard coded string value. Right Now,the enom case dataPoints has to be equal to the search query,but again,I can't figure out how to pass that data in.
Help would be appreciated!
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。