I want to fetch values of string from JSON , I am able to parse JSON to Dictionary but not able to convert into array of string
FROM SERVER
{
“ALL TEXT: [
{
"text": "hello"
},
{
"text": "hi"
},
{
"text": "how r u"
}
]
}
I only want value of text to append to my string array "textsList"
var textsList : [String]()
This is what I had tried
URLSession.shared.dataTask(with: request) { (data, response, err) in
let json = try! JSONSerialization.jsonObject(with: data!, options: .allowFragments) as! Dictionary<String, Any>
let AllText = json[“ALL TEXT”] as! [Dictionary<String, Any>]
let value = JSON(AllText)
AllText.forEach { fetch in
self.textsList.append(fetch.values) // ERROR no exact matches in call to instance method append
}
for(key, object) in value{
print(value) //output: {"text": "hello" },{"text": "hi" }
print(value.string) //output:nil
}
}.resume()
I just want to convert dictionary into array , but also alternate solution to convert JSON directly into array of string will be fine.