【问题标题】:Loop through [[String: Any]]循环 [[String: Any]]
【发布时间】:2016-10-09 19:18:38
【问题描述】:

与

let posts = json["posts"] as? [[String: Any]] ?? []
print(posts)

我明白了

[["id": 1, "title": title 1], ["id": 2, "title": title 2], ["id": 3, "title": title 3], ["id": 4, "title": title 4], ["id": 5, "title": title 5]]

如何循环获取每个id 和title 的值?

【问题讨论】:

    标签: ios json swift swift3


    【解决方案1】:

    使用for-loop 遍历posts,并确保您拥有guard 的值。

    for post in posts{
        guard let id = post["id"] as? Int,
              let title = post["title"] as? String else { continue }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-06-07
      • 2017-04-14
      • 1970-01-01
      • 1970-01-01
      • 2020-09-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多