目前,我遇到的问题是使用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解析它或者充当字典。
不幸的是我失败了。
有人能帮我吗?我是新来的,请原谅。
谢谢
发布于 2018-04-19 16:54:18
首先,您需要安全地打开响应,然后访问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)
}
}
}
}
}但我建议您看看ObjectMapper,它可以帮助您很好地使用JSON,或者您可以尝试通过苹果学习编解码。
https://stackoverflow.com/questions/49926018
复制相似问题