iOS Swift 4/来自cloudant连接的响应

iOS Swift 4/来自cloudant连接的响应,swift,parsing,cloudant,Swift,Parsing,Cloudant,目前我的问题是使用Cloudant和它来访问noSql数据库 我也会拿回来的 这是订单: let read = GetAllDocsOperation(databaseName: dbName){ (response, httpInfo, error) in if let error = error { print("Encountered an error while reading a document. Error:\(error)")

目前我的问题是使用Cloudant和它来访问noSql数据库

我也会拿回来的

这是订单:

    let read = GetAllDocsOperation(databaseName: dbName){ (response, httpInfo, error) in
        if let error = error {
            print("Encountered an error while reading a document. Error:\(error)")
        } else {

          print(response)

        }
    }

    client.add(operation:read)
以下是我的结果:

现在我不知道该怎么办了。我首先尝试用SwiftyJSON解析它,或者充当字典

不幸的是,我失败了

有人能帮我吗? 我是swift新手,请原谅


谢谢

首先需要安全地打开响应,然后访问JSON。这里的这个是手动操作,没有编码器、解码器或第三方

if let response = response as? [String: Any] {
    if let rowData = response["row"] as? [[String: Any]] {
        for row in rowData {
            if let id = row["id"] as? Int {
                print(id.description)
            } 
            if let key = row["key"] as? Int {
                print(key.description)
            }
            if let value = row["value"] as? [String: Any] {
                if let rev = value["rev"] as? String {
                     print(rev)
                }
            } 
        }
    }
}
但我建议您看看,这对您的JSON有很大帮助,或者您可以尝试一下通过Apple学习它

嗨,用您的代码做到了:)谢谢。你说得对,我现在就来看看这个话题:)