Swift3 Swift 3中的JSON解析?

Swift3 Swift 3中的JSON解析?,swift3,Swift3,我需要对这个JSON字符串进行解析,并需要获取Iphone中的所有值,如宽度、url等,有什么建议吗 [[ { "id" : "1ab66b240b5441a35f1c963c802ebc23", "sizes" : { "IPhone" : { "width" : 288, "actualHeight" : 288, "sizeName" : "IPhone", "url" : "abc1.jpg"

我需要对这个JSON字符串进行解析,并需要获取Iphone中的所有值,如宽度、url等,有什么建议吗

[[
  {
    "id" : "1ab66b240b5441a35f1c963c802ebc23",
    "sizes" : {
      "IPhone" : {
        "width" : 288,
        "actualHeight" : 288,
        "sizeName" : "IPhone",
        "url" : "abc1.jpg",
        "actualWidth" : 288,
        "height" : 360
      },
      "IPhone2" : {
        "width" : 164,
        "actualHeight" : 164,
        "sizeName" : "Large",
        "url" : "https:abc.jpg",
        "actualWidth" : 164,
        "height" : 205
      },
     }
  }
]]

感谢阅读JSON非常简单:

{}
是字典,
[]
是数组,因此所有嵌套集合类型都是字典:

为方便起见,请声明类型别名:

typealias JSONDictionary = [String : Any]

注意:不要在Swift中对循环使用丑陋的基于C样式索引的
,这是推荐的方法:

for aObject in arrJSON as! [JSONDictionary] {
并删除下一行
让aObject=..

用于解析值,它工作正常

SwiftyJSON使在Swift中处理JSON数据变得容易。例如:

let json = JSON(data: dataFromNetworking)
if let userName = json[0]["user"]["name"].string {
  //Now you got your value
}
let json = JSON(data: dataFromNetworking)
if let userName = json[0]["user"]["name"].string {
  //Now you got your value
}