如何在swift中从带有dicitionary的数组中获取值?

我想让下面的json到我的数组中以便在UITableview显示

 { MyPets = ( { breed = ""; breedvaccinationrecord = ""; "city_registration" = ""; "date_of_birth" = ""; "emergency_contacts" = ""; gender = m; "pet_id" = 475; "pet_name" = "IOS PET"; petinfo = "http://name/pet_images/"; "prop_name" = ""; "qr_tag" = 90909090; species = Canine; "vaccination_records" = ""; vaccinationrecord = "http://Name/vaccination_records/"; "vet_info" = ""; } ); } 

我使用下面的代码来获取值到数组

 if let dict = response.result.value { print(response) let petListArray = dict as! NSDictionary self.petListArray = petListArray["MyPets"] as! [NSMutableArray]} 

在cellForRowAtIndexPath中我使用此行在TableCell中的UILabel中显示名称

 cell?.petName.text = self.petListArray[indexPath.row].valueForKey("pet_name") as? String 

但它像是一样崩溃

 fatal error: NSArray element failed to match the Swift Array Element type 

我是swift 2的新手,请提前帮助我

首先将petListArray声明为Swift Array不要在Swift 使用NSMutable...集合类型。

顺便说一下命名...ListArray是多余的,我建议petListpetArray或只是pets

 var pets = [[String:Any]]() 

根对象是一个字典,关键MyPets的值是一个数组,所以MyPets

 if let result = response.result.value as? [String:Any], let myPets = result["MyPets"] as? [[String:Any]] { self.pets = myPets } 

cellForRow

 let pet = self.pets[indexPath.row] cell?.petName.text = pet["pet_name"] as? String 

高度重视使用自定义类或结构作为模型。 这避免了很多类型的铸造。