gpt4 book ai didi

ios - 展开可选的 JSON 元素使应用程序崩溃

转载 作者:行者123 更新时间:2023-11-28 12:13:23 25 4
gpt4 key购买 nike

<分区>

我在展开 JSON 嵌套数组中的可选元素时遇到问题。有问题的元素被标记为“solo_competitive_rank”和“score”。作为引用,单击一个 Controller 中的 TableView 单元格时,这些元素应显示在新的 View Controller 中。 While this works sometimes, when a cell that is selected does not have these values, the app crashes.有人可以帮我正确解开这些元素吗?

JSON 结构

struct PlayerStatsParent:Decodable{
let rankings: [PlayerStats]
}


struct PlayerStats:Decodable {
let personaname: String?
let score: Double?
let solo_competitive_rank: Int?
let avatar: String?
}

显示 View

override func viewDidLoad() {
super.viewDidLoad()
rankLabel.text = "\((playerRank?.solo_competitive_rank)!)"
scoreLabel.text = "\((playerRank?.score)!)"
}

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