gpt4 book ai didi

swift - 在 Wunderground API 中访问一个值

转载 作者:行者123 更新时间:2023-11-28 07:01:20 25 4
gpt4 key购买 nike

我正在尝试将 Wunderground 合并到我当前的项目中。我看过几个 api 教程,但我似乎无法弄清楚如何访问 API 的某个部分。例如,这是 API 的样子:

{
"response": {
"version":"0.1",
"termsofService":"http://www.wunderground.com/weather/api/d/terms.html",
"features": {
"history": 1
}
}
,
"history": {
"date": {
"pretty": "August 9, 2015",
"year": "2015",
"mon": "08",
"mday": "09",
"hour": "12",
"min": "00",
"tzname": "America/Los_Angeles"
},

假设我只想从 API 返回小时数。我该怎么做?

最佳答案

一种不用框架解析JSON的方法:

typealias JSONdic = [String: AnyObject]

NSURLConnection.sendAsynchronousRequest(NSURLRequest(URL: nsUrl), queue: NSOperationQueue.mainQueue(), completionHandler: { (_, data, _) -> Void in
if let data = data, json = data as? JSONdic, history = json["history"] as? JSONdic, hour = history["hour"] as? String {
println(hour)
}

关于swift - 在 Wunderground API 中访问一个值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31949865/

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