索引到JSON对象

时间:2015-10-27 18:05:11

标签: json swift

我有一个形状为的JSON对象:

let allSnippets = [<METDocument key: <collection: snippets, ID: xNmjQH5N3HbomnATk>, fields: {
        text = "First snippet";
    }>, <METDocument key: <collection: snippets, ID: KvQWnWfyto5iXXsni>, fields: {
        text = "Second snippet";
    }>]

如何将其编入索引,例如从字段中获取文本“Second snippet”?

我试过了:

    let json = JSON(allSnippets)
    if let text = json[1]["text"].string{
        print(text)
    }

但这没效果。

0 个答案:

没有答案