【问题标题】:How to get this subJson using SwiftyJSON?如何使用 SwiftyJSON 获取这个 subJson?
【发布时间】:2016-05-18 16:19:28
【问题描述】:
"groups" : {
    "232" : {
      "name" : "John",
      "age" : "22"
      }
    },
    "143" : {
      "name" : "Dylan",
      "age" : "22"
      }
    }

如何使用 swiftyJSON 获取“名称”?我得到了 id 值,但 ["name"] 的代码总是为零:

        for (results,subJson):(String, JSON) in json["groups"] {
                    let id = results
                    print(id) //--> 232
                    let name = subJson["\(id)"]["name"].string
                    print(name) //--> nil
         }

【问题讨论】:

    标签: json swift swifty-json


    【解决方案1】:

    name键在subJson里面,去掉id下标:

    for (id, subJson):(String, JSON) in json["groups"] {
        print(id)
        if let name = subJson["name"].string {
            print(name)
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-04-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多