gpt4 book ai didi

ios - 使用 Codable 解码具有多个 key 的 JSON

转载 作者:行者123 更新时间:2023-11-28 13:49:47 24 4
gpt4 key购买 nike

我在 iCloud 中存储了几个字节类型的 JSON 文件。希望到目前为止是正确的。

我必须获取那些 CKRecord,然后解析它们并使用存储在 JSON 中的值显示图表。我能够从 iCloud 获取数据,但我没有运气解析这个 JSON。

{"00:00": 17, "00:10": 16, "00:20": 17, "00:30": 16, "00:40": 16, "00:50": 17, "01:00": 16, "01:10": 16, "01:20": 16, "01:30": 16, "01:40": 17, "01:50": 17, "02:00": 18, "02:10": 18, "02:20": 17, "02:30": 17, "02:40": 17, "02:50": 17, "03:00": 16, "03:10": 17, "03:20": 16, "03:30": 16, "03:40": 17, "03:50": 16, "04:00": 16, "04:10": 16, "04:20": 16, "04:30": 16, "04:40": 16, "04:50": 18, "05:00": 17, "05:10": 16, "05:20": 17, "05:30": 17, "05:40": 17, "05:50": 17, "06:00": 17, "06:10": 17, "06:20": 16, "06:30": 16, "06:40": 17, "06:50": 15, "07:00": 15, "07:10": 15, "07:20": 14, "07:30": 15, "07:40": 13, "07:50": 11, "08:00": 8, "08:10": 8, "08:20": 7, "08:30": 5, "08:40": 4, "08:50": 4, "09:00": 2, "09:10": 2, "09:20": 9, "09:30": 8, "09:40": 7, "09:50": 7, "10:00": 5, "10:10": 4, "10:20": 6, "10:30": 5, "10:40": 4, "10:50": 4, "11:00": 3, "11:10": 2, "11:20": 2, "11:30": 1, "11:40": 2, "11:50": 1, "12:00": 1, "12:10": 2, "12:20": 3, "12:30": 3, "12:40": 2, "12:50": 3, "13:00": 1, "13:10": 0, "13:20": 1, "13:30": 0, "13:40": 3, "13:50": 2, "14:00": 3, "14:10": 4, "14:20": 3, "14:30": 6, "14:40": 4, "14:50": 6, "15:00": 5, "15:10": 7, "15:20": 7, "15:30": 7, "15:40": 7, "15:50": 6, "16:00": 7, "16:10": 8, "16:20": 8, "16:30": 6, "16:40": 5, "16:50": 5, "17:00": 5, "17:10": 4, "17:20": 4, "17:30": 6, "17:40": 6, "17:50": 5, "18:00": 6, "18:10": 7, "18:20": 4, "18:30": 3, "18:40": 3, "18:50": 5, "19:00": 5, "19:10": 3, "19:20": 4, "19:30": 4, "19:40": 2, "19:50": 4, "20:00": 1, "20:10": 2, "20:20": 2, "20:30": 1, "20:40": 3, "20:50": 2, "21:00": 4, "21:10": 4, "21:20": 7, "21:30": 7, "21:40": 6, "21:50": 7, "22:00": 8, "22:10": 7, "22:20": 8, "22:30": 9, "22:40": 10, "22:50": 10, "23:00": 10, "23:10": 9, "23:20": 9, "23:30": 10, "23:40": 10, "23:50": 10}

我以前使用 Codable 来使用 Swift 解析 JSON,但这种情况不同。我有很多键是数字,但我真的不知道如何处理。

最佳答案

你可以试试

let res = try? JSONDecoder().decode([String:Int].self,from:data)

关于ios - 使用 Codable 解码具有多个 key 的 JSON,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54843701/

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