简体   繁体   中英

Problems in parse JSON array

I have this JSON:

{
  "myData" : [
    [
      {
        "text" : "lorem ipsum",
        "id" : "myId"
      }
    ]
  ]
}

And I want to get "text" and "id" values with SwiftyJSON.

My code:

    Alamofire.request(url, method: .post, parameters: parameters, encoding: URLEncoding(destination: .httpBody), headers: headers).responseJSON { (response) in
        switch response.result {
        case .success(let value):
            let json = JSON(value)
            let id = json //json["myData"]["id"]... how get "id" ?
            print(id)
    }

看来您正在访问一个数组数组,因此需要像let id = json["myData"][0][0]["id"]下标所需的元素。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM