Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/95.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios JSON未在swift中更新_Ios_Json_Swift - Fatal编程技术网

Ios JSON未在swift中更新

Ios JSON未在swift中更新,ios,json,swift,Ios,Json,Swift,我正在开发一个swift应用程序,它使用来自url的JSON。但是在JSON中进行更改时,它不会在应用程序中更新。这是我正在使用的代码 let urlAsString = "http://domain/json.json" let url = NSURL(string: urlAsString)! let urlSession = NSURLSession.sharedSession() let jsonQuery = urlSession.dataTaskWithUR

我正在开发一个swift应用程序,它使用来自url的JSON。但是在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()

我认为苹果正在缓存旧值

共享会话可能会缓存数据并阻止刷新。您需要创建自己的NSURLSession并设置请求缓存策略。请参阅此答案以获取代码

var jsonResult = NSJSONSerialization.JSONObjectWithData(data, options: NSJSONReadingOptions.MutableContainers, error: &err) as NSDictionary