我已经将
Xcode从7更新为8,将
Swift从2.3更新为3.
我在让名字=候选人[“候选人姓名”]时得到这个错误!:
type nsfastenumerationiterator.element aka any has no subscript members
let url = URL(string: "https://website.com") let data = try? Data(contentsOf: url!) var tmpValues = try! JSONSerialization.jsonObject(with: data!,options: JSONSerialization.ReadingOptions.mutableContainers) as! NSArray tmpValues = tmpValues.reversed() as NSArray reloadInputViews() for candidate in tmpValues { if ((candidate as? NSDictionary) != nil) { let names = candidate["CandidateName"]! //self.values.append(candidate["CandidateName"]) self.values.append(name!) print(name) } }
我认为你的循环应该是这样的.这对我有用.但请确保var tmpValues.
原文链接:https://www.f2er.com/swift/318635.htmlfor candidate in (tmpValues as? [[String:Any]])! { if ((candidate as? NSDictionary) != nil) { let names = candidate["CandidateName"]! as? String //self.values.append(candidate["CandidateName"]) self.values.append(name!) print(name) } }