0
我在這裏使用了一些JSON代碼。這種解析格式僅返回字典。我需要解析我的數組; [{「id」:「1」,「Venue_Name」:「Fashon Show」}]。我如何從數組中解析字典而不是使用這種格式的字典?解析數組中的JSON字典
let urlAsString = "http://date.jsontest.com"
let url: NSURL = NSURL(string: urlAsString)
let urlSession = NSURLSession.sharedSession()
//2
let jsonQuery = urlSession.dataTaskWithURL(url, completionHandler: { data, response, error -> Void in
if (error != nil) {
println(error.localizedDescription)
}
var err: NSError?
// 3
var jsonResult = NSJSONSerialization.JSONObjectWithData(data, options: NSJSONReadingOptions.MutableContainers, error: &err) as NSDictionary
if (err != nil) {
println("JSON Error \(err!.localizedDescription)")
}
// 4
let jsonDate: String! = jsonResult["date"] as NSString
let jsonTime: String! = jsonResult["time"] as NSString
dispatch_async(dispatch_get_main_queue(), {
self.dateLabel.text = jsonDate
self.timeLabel.text = jsonTime
})
})
// 5
jsonQuery.resume()
}