I am trying to convert json array of objects to a Dictionary,
I have this code:
func load() { //this function is the first that is executed
getActivities {
(response) in
self.loadActivities(response as NSArray)
}
}
func getActivities(callback:(NSDictionary) -> ()){ //the next url contains the json array of objects
request("http://localhost/llancaActivity/public/activity/getListJSON/0/2", callback: callback)
}
func request(url:String, callback:(NSDictionary) -> ()){
var nsURL : NSURL = NSURL(string: url)!;
let task = NSURLSession.sharedSession().dataTaskWithURL(nsURL){
(data, response, error) in
var error: NSError?
var response = NSJSONSerialization.JSONObjectWithData(data, options: NSJSONReadingOptions.MutableContainers, error: &error) as NSDictionary;
callback(response);
}
task.resume();
}
func loadActivities(activities:NSArray){
for activity in activities {
println(activity["id"]); //<-- These line never is executed!!!!
}
}
If I visit with my browser the next URL: http: // localhost/llancaActivity/public/activity/getListJSON/0/2
I have the next response:
[{"id":"3","title":"Confer\u00e8ncia de meteorologia \u201cEl canvi clim\u00e0tic\u201d","description":"Hora: 19h\nLloc: Sala de Confer\u00e8ncies de la Casa de Cultura","start_date":"2014-12-13","end_date":"2014-12-13","id_category":null},{"id":"4","title":"Espectacle a favor de la Marat\u00f3 de TV3","description":"Hora: 17h\nEntrada: la voluntat\nLloc: Sala d\u2019Actes de la Casa de Cultura\nOrganitza: Associaci\u00f3 de Puntaires de Llan\u00e7\u00e0\nCol\u00b7labora: Entitats i Associacions de Llan\u00e7\u00e0 i l\u2019Ajuntament de Llan\u00e7\u00e0","start_date":"2014-12-13","end_date":"2014-12-13","id_category":null}]
Please, sorry for my english...
responseanderrorvariables? What do they contain?