Analisando a matriz JSON em swift
Estou tentando analisar o seguinte JSON
[
{
"id": "5",
"name": "Test",
"team1": "thingy team",
"team2": "clicky team",
"category": "4",
"end_date": "1415217600",
"cat_name": "new thingy",
"team1_bets": 1,
"team2_bets": 1
}
]
Este é o JSON que estou obtendo dos meus serviços da web e estou usando o seguinte código para analisá-lo:
let urlAsString = "http://codespikestudios.com/betting_app/bet/get_events/4"
//let urlAsString = "http://api.topcoder.com/v2/challenges?pageSize=2"
let url: NSURL = 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)")
}
println(jsonTime)
})
jsonQuery.resume()
Eu estou recebendo o seguinte erro
A operação não pôde ser concluída. (Erro NSURLErrorDomain -1005.) Erro fatal: inesperadamente encontrado nulo ao desembrulhar um valor opcional
Como posso resolver isso?