swift - Extra argument 'Error' in call with Json -
i'm trying data themoviedb api error json code. error " argument 'error' in call" code
var err: nserror? private func reload() { let requesturl = "https://www.themoviedb.org/search/remote/multi?query=exterminador%20do%20futuro&language=en" let config = nsurlsessionconfiguration.defaultsessionconfiguration() let session = nsurlsession(configuration: config) let request = nsurlrequest(url: nsurl(string: requesturl)!) let task = session.datataskwithrequest(request, completionhandler: { (data, response, error) -> void in if let error = error { print("###### error ######") } else { if let json = nsjsonserialization.jsonobjectwithdata(data, options: .allowfragments, error: nil) as? [nsdictionary] { movie in json { let name = movie["name"] as! string let posterpath = movie["poster_path"] as! string println(name) // "terminator genisys" println(posterpath) // "/5ju9ytzjyr3zmclgmvm9q4geqbd.jpg" } } } }) task.resume() } } thank you!
hard tell when you´re not adding more code, wrap call in do-statement , should this
let parsedresult: anyobject? { parsedresult = try nsjsonserialization.jsonobjectwithdata(data, options: nsjsonreadingoptions.allowfragments) } catch let error nserror { parsingerror = error parsedresult = nil } update
had few errors in code
- you had
{@ end - you had parameter in
nsjonserializationcall (error parameter) - some errors optionals
but have updated code , can try it:
var err: nserror? private func reload() { let requesturl = "https://www.themoviedb.org/search/remote/multi?query=exterminador%20do%20futuro&language=en" let config = nsurlsessionconfiguration.defaultsessionconfiguration() let session = nsurlsession(configuration: config) let request = nsurlrequest(url: nsurl(string: requesturl)!) let task = session.datataskwithrequest(request, completionhandler: { (data, response, error) -> void in if let error = error { print("###### error ######") } else { { if let json = try nsjsonserialization.jsonobjectwithdata(data!, options: nsjsonreadingoptions.allowfragments) as? [nsdictionary]{ movie in json { let name = movie["name"] as! string let posterpath = movie["poster_path"] as! string print(name) // "terminator genisys" print(posterpath) // "/5ju9ytzjyr3zmclgmvm9q4geqbd.jpg" } } } catch let error nserror { } } }) task.resume() }
Comments
Post a Comment