SWIFT - String based Key-Value Array decoding?

42 Views Asked by At

I have a String based Key-Value Array inside of a String, and I want to decoded it and assign the value to an existing array in Swift 4.2. For example:

let array: [String:String] = []
let stringToDecode = “[\“Hello\”:\”World\”, \"Key\":\"Value\"]”

// I want ‘array’ to be assigned 
// to the value that is inside 
// ‘stringToDecode’

I’ve tried the JSON decoder, but it couldn’t decode it. Is there a simple way to do this? Thank you.

1

There are 1 best solutions below

1
Jack Campbell On

Try using a library like SwiftyJson, it makes working with json much easier.