Does Swift provide a way to convert a raw String like this
"[\"John\",\"Anna\",\"Tom\"]"
to an Array of strings ([String]
)?
I've looked for a way to do it over StackOverflow, but in that specific way, I could not find an answer :/
Does Swift provide a way to convert a raw String like this
"[\"John\",\"Anna\",\"Tom\"]"
to an Array of strings ([String]
)?
I've looked for a way to do it over StackOverflow, but in that specific way, I could not find an answer :/
Code Different answer is probably a recommended way to do it nowadays (Swift 4+).
For reference, here is a classic way to do the same, compatible with older Swift versions:
According to Itai Ferber,
JSONDecoder
usesJSONSerialization
under the hood, so it should do pretty much the same as Code Different answer.On Swift 4 and later, use
JSONDecoder
: