hI,
I'm getting JSON from a web service in the following format:
{"wards":[{"ward":[{"id":"1", "name":"Ward A"},{"id":"2", "name":"Ward B"},{"ID":"3", "name":"Ward C"}]}]}
When i'm trying to assing it to my custom object:
class Ward {
var id:Int
var name:String
init(id:Int, name:String){
self.id = id
self.name = name}
}
I'm getting the following error on line 03 \: Could not cast value of type '__NSArrayM' (0x10e710b60) to 'NSDictionary' (0x10e710fe8).
func loadWards(wards:NSArray){
for ward in wards{
let ward2 = ward["ward"]! as! NSDictionary
let id = Int(ward2["id"]! as! String)!
let name = ward2["name"]! as! String
let wardObj = Ward(id: id, name: name)
wardsCollection.append(wardObj)
dispatch_async(dispatch_get_main_queue()) {
self.tableView.reloadData()
}
}
}
Is there something i'm doing incorrect with assigning the values?
Thanks