Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Swift 如何在数组中解析json存储_Swift_Swift3 - Fatal编程技术网

Swift 如何在数组中解析json存储

Swift 如何在数组中解析json存储,swift,swift3,Swift,Swift3,我有来自服务器的响应,我想过滤它并使用swift存储在阵列中。请帮助我怎么做 self.countryArrayvalue = (json?["list"] as! [Dictionary<String, Any>] as! NSArray) as! [Dictionary<String, Any>] 你铸造的铸件太多,而不是一个 self.countryArrayvalue = json?["list"] as! [[String: Any]] 现在,要获得国家名称

我有来自服务器的响应,我想过滤它并使用swift存储在阵列中。请帮助我怎么做

self.countryArrayvalue = (json?["list"] as! [Dictionary<String, Any>] as! NSArray) as! [Dictionary<String, Any>]

你铸造的铸件太多,而不是一个

self.countryArrayvalue = json?["list"] as! [[String: Any]]
现在,要获得国家名称数组,请尝试以下方法

self.countryNamesArray = self.countryArrayvalue.flatMap { $0["country_name"] as? String }
self.countryNamesArray = self.countryArrayvalue.flatMap { $0["country_name"] as? String }