【问题标题】:Nested Dictionary in my swift application在我的 swift 应用程序中嵌套字典
【发布时间】:2018-09-23 05:55:53
【问题描述】:

enter image description here

如何访问这些图片链接?

我试过 print(pokemonDictionary["sprites"]["back_default"] 但我得到一个错误 可选类型“任何?”的值未拆封;你的意思是用'!'还是“?”?

【问题讨论】:

  • 首先你必须发布代码而不是图片

标签: swift dictionary


【解决方案1】:

你可以试试

if  let sprites = pokemonDictionary["sprites"] as? [String:Any] {

      print(sprites)

   if  let backImgUrl = sprites["back_default"] as? String {

        print(backImgUrl)
    }

}

您还应该在除 main 之外的线程中运行名为 CallUrl 的函数,因为 Data(contentsOf:) 同步运行并阻塞主线程

【讨论】:

  • 问题解决了!谢谢!
猜你喜欢
  • 2019-05-02
  • 2021-02-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-07-10
  • 2018-10-26
  • 2014-09-13
相关资源
最近更新 更多