как я могу получить значения в зависимости от значения в дочернем узле.Например, если у меня есть JSON, как это
{
"id": 14,
"name": "АBC",
"picture": 44,
"group": {
"id": 2,
"gname": "AAA",
"pic": 1
}
},
{
"id": 14,
"name": "АBC",
"picture": 44,
"group": {
"id": 1,
"gname": "BB",
"pic": 2
}
}...
]
я хочу получить список всех имен, где дочернее значение равно "AAA"
Я знаю, как прочитать все значения для имени, но я не знаюне знаю, как их читать, если мне нужны только имена, которые имеют конкретное значение gname.
Вот код:
import UIKit
import Alamofire
import SwiftyJSON
class ThirdViewController : UITableViewController {
var dataInfo = [[String: AnyObject]]()
let url = "http://XXX"
let header = ["X": "XXX"]
override func viewDidLoad() {
super.viewDidLoad()
self.tableView.rowHeight = 50
getData(url: url)
self.tableView.reloadData()
}
override func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return dataInfo.count
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell2", for: indexPath) as! Cell2
cell.lblName?.text = dataInfo[indexPath.row]["name"] as? String
return cell
}
func getData(url: String) {
Alamofire.request(url, method: .get, headers: header)
.responseJSON { response in
if response.result.isSuccess {
print("Sucess! Got the data")
let dataJSON : JSON = JSON(response.result.value!)
self.updateData(json: dataJSON)
} else {
print("Error: \(String(describing: response.result.error))")
}
}
self.tableView.reloadData()
}
func updateData(json : JSON) {
if let data = json[].arrayObject {
self.dataInfo = data as! [[String: AnyObject]]
self.tableView.reloadData()
}
else {
print("cannot connect to the server")
}
}
}
Буду признателен, если кто-нибудь сможет мне помочь.