gpt4 book ai didi

ios - 如何从字典数组中获取数据 - swift

转载 作者:可可西里 更新时间:2023-10-31 23:56:40 25 4
gpt4 key购买 nike

如何从这个数组中获取数据?这里有一个包含一些键值对的数组,一些键包含一个字典数组。

 var dataArray = [
["teamName":"Arsenal",
"image":"imageName",
"nextMatch":"in 2 days",
"matches":[
["oppositeTeam":"teamName",
"matchTimings":"121212",
"matchId":"ID 213432"],
["oppositeTeam":"teamName",
"matchTimings":"121212",
"matchId":"ID 213432"]
],
"fixtures":[
["oppositeTeam":"teamName",
"oppositeTeamScore":"7",
"HomeTeamScore":"4",
"HomeTeamCards":"True",
"oppositeTeamCards":"false",
"fixturesId":"ID 213432"],

]
],["teamName":"Chelsea",
"image":"imageName",
"nextMatch":"in 2 days",
"matches":[["oppositeTeam":"teamName",
"matchTimings":"121212",
"matchId":"ID 213432"],["oppositeTeam":"teamName",
"matchTimings":"121212",
"matchId":"ID 213432"]
],"fixtures":[["oppositeTeam":"teamName",
"oppositeTeamScore":"7",
"HomeTeamScore":"4",
"HomeTeamCards":"True",
"oppositeTeamCards":"false",
"fixturesId":"ID 213432"],["oppositeTeam":"teamName",
"oppositeTeamScore":"7",
"HomeTeamScore":"4",
"HomeTeamCards":"True",
"oppositeTeamCards":"false",
"fixturesId":"ID 213432"]
]
],["teamName":"India",
"image":"imageName",
"nextMatch":"null",
"matches":[],
"fixtures":[]
]]

我试过了,但我无法从这个数组中获取数据。

最佳答案

你需要像这样使用模型

struct Team {
let teamName:String
let image:String
let nextMatch:String
let matches:[Match]?
let fixtures:[Fixture]?
}

struct Match {
let oppositeTeam:String
let matchTimings:String
let matchId:String
}

struct Fixture {
let oppositeTeam:String
let oppositeTeamScore:String
let HomeTeamScore:String
let HomeTeamCards:String
let oppositeTeamCards:String
let fixturesId:String
}

接下来你需要在swift中了解Codeable,我在下面附上了一篇文章

Codeable Tutorial in swift

关于ios - 如何从字典数组中获取数据 - swift,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53257071/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com