我有一个形状为的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)
}
但这没效果。