gpt4 book ai didi

ios - Swift:在没有 key 的情况下解析 JSON 字符串

转载 作者:搜寻专家 更新时间:2023-11-01 06:18:57 24 4
gpt4 key购买 nike

我想解析 json 字符串如下,我想知道如何打印 [times] 值

Json 字符串:

{
date: "2014-08-13",
method: "Makkah: Umm al-Qura University, Makkah",
latitude: "30.0599153",
longtude: "31.2620199",
timezone: "+3",
times: [
"04:52",
"06:21",
"13:00",
"16:36",
"19:38",
"19:38",
"21:08"
] }

这是我的代码:

let json = try NSJSONSerialization.JSONObjectWithData(data!, options:.AllowFragments)

let todayDate = json["date"]
let method = json["method"]
let latitude = json["latitude"]
let longtude = json["longtude"]
let timezone = json["timezone"]

所以问题是,如何打印时间,谢谢

最佳答案

let times = json["times"] as! [String]

for time in times {
print(time)
}

或在一行中

times.forEach{ print($0) }

关于ios - Swift:在没有 key 的情况下解析 JSON 字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38085014/

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