[英]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.我在字符串中有一个基于字符串的键值数组,我想对其进行解码并将值分配给 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.我试过 JSON 解码器,但它无法解码。 Is there a simple way to do this?
有没有一种简单的方法可以做到这一点? Thank you.
谢谢你。
Try using a library like SwiftyJson , it makes working with json much easier.尝试使用SwiftyJson之类的库,它可以更轻松地使用 json。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.