【发布时间】:2015-03-21 09:26:34
【问题描述】:
我正在开发一个使用来自 url 的 JSON 的 swift 应用程序。但是在 JSON 中进行更改时,它不会在应用程序中更新。这是我正在使用的代码
let urlAsString = "http://domain/json.json"
let url = NSURL(string: urlAsString)!
let urlSession = NSURLSession.sharedSession()
let jsonQuery = urlSession.dataTaskWithURL(url, completionHandler: { data, response, error -> Void in
if (error != nil) {
println(error.localizedDescription)
}
var err: NSError?
var jsonResult = NSJSONSerialization.JSONObjectWithData(data, options: NSJSONReadingOptions.MutableContainers, error: &err) as NSDictionary
if (err != nil) {
println("JSON Error \(err!.localizedDescription)")
}
var i = 1
while i <= jsonResult.count / 2 {
let title = i.description + "t"
self.feeds.insert(jsonResult[i.description] as NSString, atIndex: 0)
self.feedst.insert(jsonResult[title] as NSString, atIndex: 0)
i++
}
dispatch_async(dispatch_get_main_queue(), {
self.tableView.reloadData()
})
})
jsonQuery.resume()
我尝试进行 som 调试并提出问题可能出在这部分:
var jsonResult = NSJSONSerialization.JSONObjectWithData(data, options: NSJSONReadingOptions.MutableContainers, error: &err) as NSDictionary
我认为 Apple 正在缓存旧值
【问题讨论】: