我有这个JSON:
{
"myData" : [
[
{
"text" : "lorem ipsum",
"id" : "myId"
}
]
]
}
我想用SwiftyJSON获取“文本”和“ id”值。
我的代码:
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)
}
答案 0 :(得分:2)
您似乎正在访问一个数组数组,因此需要像let id = json["myData"][0][0]["id"]
下标所需的元素。