简体   繁体   中英

SWIFT - String based Key-Value Array decoding?

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM