Swift:如何将字符串转换为字典

Dis*_*ame 2 dictionary swift

我有一个字典,我转换为字符串将其存储在数据库中.

        var Dictionary =
    [
        "Example 1" :   "1",
        "Example 2" :   "2",
        "Example 3" :   "3"
    ]
Run Code Online (Sandbox Code Playgroud)

我用的是

Dictionary.description
Run Code Online (Sandbox Code Playgroud)

得到字符串.

我可以完美地将它存储在数据库中,但是当我读回它时,显然它是一个字符串.

"[Example 2: 2, Example 3: 3, Example 1: 1]"    
Run Code Online (Sandbox Code Playgroud)

我想把它转换回来我可以评估它

Dictionary["Example 2"]
Run Code Online (Sandbox Code Playgroud)

我该怎么做呢?

谢谢

gre*_*heo 6

descriptionSDK版本的文本不保证是稳定的,所以我不会依赖它.

最好的办法是使用JSON作为NSJSONSerialization的中间格式.从字典转换为JSON字符串并返回.