Swift - JSON array values -


i getting following json values in output:

[["category_title": shelly], ["category_title": thaddeus], ["category_title": chantale], ["category_title": adara], ["category_title": mariko], ["category_title": felicia]] 

but want below:

["shelly","thaddeus","chantale", "adara","mariko","felicia"] 

i have following swift code. please me above output.

func successgettermsdata(response: any){     var userrole : string = ""     var arrayofdetails = response as? [[string: any]] ?? []      userrole = arrayofdetails as? string ?? ""     print(arrayofdetails) } 

you have map array of dictionary arrayofdetails array of string. flatmap ignores missing key.

if let arrayofdetails = response as? [[string: string]] {     let userrole = arrayofdetails.flatmap { $0["category_title"] }     print(userrole) } 

Comments

Popular posts from this blog

python Tkinter Capturing keyboard events save as one single string -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

javascript - Z-index in d3.js -