【发布时间】:2021-07-04 15:54:01
【问题描述】:
我在视图控制器中调用了树段。 OPEN, CLOSED, ALL
我的 JSON 响应如下:
{
"jsonrpc": "2.0",
"result": {
"data": {
"open": [
{
"user_id": "10",
"request_title": "Title-2",
"category": "4",
"gender": "M",
"location": "On earth",
"from_date": "2021-04-09",
}
{
"user_id": "10",
"request_title": "Title-2",
"category": "4",
"gender": "M",
"location": "On earth",
"from_date": "2021-04-09",
}
........
]
"close": [
{
"user_id": "10",
"request_title": "Title-2",
"category": "4",
"gender": "M",
"location": "On earth",
"from_date": "2021-04-09",
}
........
]
"all": [
{
"user_id": "10",
"request_title": "Title-2",
"category": "4",
"gender": "M",
"location": "On earth",
"from_date": "2021-04-09",
}
{
"user_id": "10",
"request_title": "Title-2",
"category": "4",
"gender": "M",
"location": "On earth",
"from_date": "2021-04-09",
}
........
]
}
}
}
在这里我能够得到 JSON 响应.. 以及低于 i am getting "open" values and adding them in requestsArrayto show in tableview.. but now thisrequestsArraywant to show inopen` 段,就像关闭段中的相同关闭值..如何做到这一点
if let code = ((resp.dict?["result"] as? [String : Any])){
let totalData = code["data"] as? [String : Any]
if let open = totalData?["open"] as? [[String : Any]]{
for (value) in open {
self?.title_req = value["request_title"] as? String
self?.gender = value["gender"] as? String
self?.location = value["location"] as? String
self?.requestsArray.append(AppliedRequestCellData(request_title: self?.title_req, gender: self?.gender, location: self?.location))
}
DispatchQueue.main.async {
self.tableView.reloadData()
} }
我的片段如下所示
hmSegment.indexChangeBlock = { index in
print("in index segment")
print(index)
if index == 0{
// here how to show JSON `open` response in tableview
}
if index == 1{
// here how to show JSON `close` response in tableview
}
if index == 2{
// here how to show JSON `all` response in tableview
}
}
请帮助我在 tableviewview 中使用段来鞋 JSON 响应
【问题讨论】:
标签: json swift tableview segment