gpt4 book ai didi

json - 解释 JSON 结构时出现问题 | swift

转载 作者:行者123 更新时间:2023-11-30 10:39:53 25 4
gpt4 key购买 nike

我有以下 JSON 结构,用于填充 tableView

我需要让我的 Swift 应用程序能够正确解释数据,但由于某种原因,我无法让它工作(tableView 为空)

JSON 结构:

    struct Pickup_EnRoute: Codable {
let name, sumValue: String, sumTotal: String

enum CodingKeys: String, CodingKey {
case name
case sumValue = "sumValue"
case sumValue = "sumTotal"
}
}

JSON 是什么样的:

[{"name":"Jake","sumValue":"10084.14"}, 
{"name":"Jack","sumValue":"9428.08"},{"sumTotal":19512.22}]

注意 JSON 数组中 sumTotal 没有“”(引号)

最佳答案

在 JSON 中,“sumTotal”具有 Double 类型,并且您的结构将 sumTotal 定义为 String 类型。因此将 sumTotal: String 更改为 sumTotal: Double

关于json - 解释 JSON 结构时出现问题 | swift ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57050283/

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