swift - How to alarmofire parsing json store in Array -


i have response server want filter , store in array using swift. please how it.

self.countryarrayvalue = (json?["list"] as! [dictionary<string, any>] as! nsarray) as! [dictionary<string, any>] 

now want country name self.countryarrayvalue , store in array.

response is:

{   "error": false,   "error_code": 200,   "list": [     {       "country_id": "1",       "country_name": "afghanistan",       "iso_code": "af"     },     {       "country_id": "2",       "country_name": "aland islands",       "iso_code": "ax"     },     {       "country_id": "3",       "country_name": "albania",       "iso_code": "al"     } ] } 

you making many casting instead of single one.

self.countryarrayvalue = json?["list"] as! [[string: any]] 

now array of country name try way.

self.countrynamesarray = self.countryarrayvalue.flatmap { $0["country_name"] as? string } 

Comments

Popular posts from this blog

inversion of control - Autofac named registration constructor injection -

verilog - Systemverilog dynamic casting issues -

ios - Change Storyboard View using Seague -