0
私は質問があります。私はJSONを解析しようとしています。しかし、私はエラーが発生しました。これは「この関数の関数型ではない値を呼び出すことはできません」ということです。この行では、completionHandler(modelList) "私を助けてくれますか?迅速な解析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()
}
}