0
我有一個問題,我試圖解析JSON.However,我得到一個錯誤。在這行「completionHandler(modelList)」中稱爲「Can not call value of non-function type'[Movie]'」你能幫我嗎?關於swift解析JSON
這是我的班;
class Movie {
var type : String?
var title: String?
var thumbnail: String?
var id: String?
init(Dictionary : [String:AnyObject]){
self.title = Dictionary["Title"] as? String
self.id = Dictionary["Id"] as? String
self.type = Dictionary["Type"] as? String
}
static func fetchData(completionHandler: ([Movie])) ->() {
let urlString = "http://tcm-api.azurewebsites.net/api/movie/search?term='Batman'&page=1"
NSURLSession.sharedSession().dataTaskWithURL(NSURL(string: urlString)!) { (data, response, error) -> Void in
if error != nil {
print(error)
return
}
do {
var modelList = [Movie]()
let json = try NSJSONSerialization.JSONObjectWithData(data!, options: .MutableContainers)
for resultDictionary in json["Data"]!!["Results"] as! [[String : AnyObject]] {
let model = Movie(Dictionary: resultDictionary)
modelList.append(model)
}
dispatch_async(dispatch_get_main_queue()) {
completionHandler(modelList)
}
} catch {
print(error)
}
}.resume()
}
}