gpt4 book ai didi

ios - 为什么我的 JSON URL 不输出 JSON 数据?

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

我已经检查了 URL 并且它有效,但是当我尝试输出 readableJSON 时,它是空的?!

这是我的输出:

Not empty now
2016-02-20 10:19:29.162 ThisLondon[55922:4080604] the URL: [

]
2016-02-20 10:19:29.162 ThisLondon[55922:4080604] 0

这是我的代码:

selectedTube = "Circle"
let url = NSURL(string: "https://api.tfl.gov.uk/Line/\(selectedTube)/Arrivals?app_id=6573044a&app_key=7a97df35339dc68625384077a5e07304")
let jsonData = NSData(contentsOfURL: url!)
let readableJSON = JSON(data: jsonData!, options: NSJSONReadingOptions.MutableContainers, error: nil)

NSLog("the URL: \(readableJSON)")

最佳答案

尝试使用这个:

    let selectedTube = "circle"
let headers = ["cache-control": "no-cache",]

let request = NSMutableURLRequest(URL: NSURL(string: "https://api.tfl.gov.uk/Line/\(selectedTube)/Arrivals?app_id=6573044a&app_key=7a97df35339dc68625384077a5e07304")!,
cachePolicy: .UseProtocolCachePolicy,
timeoutInterval: 10.0)
request.HTTPMethod = "GET"
request.allHTTPHeaderFields = headers

let session = NSURLSession.sharedSession()
let dataTask = session.dataTaskWithRequest(request, completionHandler: { (data, response, error) -> Void in
if (error != nil) {
print(error)
} else {
let httpResponse = response as? NSHTTPURLResponse
print(httpResponse)
}
})

dataTask.resume()

关于ios - 为什么我的 JSON URL 不输出 JSON 数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35521858/

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