如何为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 (将#修改为@)