Convert array string to array in Swift

Viewed 32

I have string:

content (String) : "[{id: \"10884\", name: \"Henry\"}, {id: \"85474\", name: \"Jack\"}]"

How can I convert this string to array

Desired results:

[{id: "10884", name: "Henry"}, {id: "85474", name: "Jack"}]

I'm trying:

let data = content.data(using: .utf8, allowLossyConversion: false)

let stringsArray = try? JSONSerialization.jsonObject(with: data!, options: .mutableContainers) as? [String: AnyObject]

print(stringsArray)

But stringsArray print is nil

I'm using swift version 5

I'm newbie IOS. Many thanks

0 Answers
Related