Ниже приведен код, который я пытался извлечь из объекта JSON. Я хочу только данные со статусом! = Статические и показать, что в tableView
postman response
[
{
"id": 249,
"name": "aBrush your teeth",
"desc": "Brush your teeth",
"reward": "1.00",
"sched": "2015-01-01T08:00:00+08:00",
"parent": "",
"type": "",
"child": "",
"occurrence": {
"name": "once"
},
"status": {
"name": "static"
},
"date_created": "2018-04-25T14:27:20.405928+08:00",
"date_modified": "2018-04-26T11:56:02.030647+08:00"
},
{
"id": 250,
"name": "Brush your teeth",
"desc": "Brush your teeth",
"reward": "1.00",
"sched": "2015-01-01T08:00:00+08:00",
"parent": "",
"type": "",
"child": "",
"occurrence": {
"name": "once"
},
"status": {
"name": "static"
},
"date_created": "2018-04-25T14:28:49.780354+08:00",
"date_modified": "2018-04-26T11:56:05.616333+08:00"
},
{
"id": 252,
"name": "Brush your teeth",
"desc": "Brush your teeth",
"reward": "1.00",
"sched": "2015-01-01T08:00:00+08:00",
"parent": "",
"type": "",
"child": "",
"occurrence": {
"name": "once"
},
"status": {
"name": "static"
},
"date_created": "2018-04-25T14:31:02.274405+08:00",
"date_modified": "2018-04-26T11:59:57.676148+08:00"
},
{
"id": 253,
"name": "Brush your teeth",
"desc": "Brush your teeth",
"reward": "1.00",
"sched": "2015-01-01T08:00:00+08:00",
"parent": "",
"type": "",
"child": "",
"occurrence": {
"name": "once"
},
"status": {
"name": "static"
},
"date_created": "2018-04-25T14:34:37.097498+08:00",
"date_modified": "2018-04-26T09:42:24.633359+08:00"
},
{
"id": 254,
"name": "Brush your teeth",
"desc": "Brush your teeths",
"reward": "1.00",
"sched": "2015-01-01T08:00:00+08:00",
"parent": "",
"type": "",
"child": "",
"occurrence": {
"name": "once"
},
"status": {
"name": "static"
},
"date_created": "2018-04-25T14:36:53.766088+08:00",
"date_modified": "2018-04-26T11:56:15.757769+08:00"
},
{
"id": 260,
"name": "chorename",
"desc": "{\n \"questions\" : [\n {\n \"b\" : 2,\n \"a\" : 1\n },\n {\n \"b\" : 3,\n \"a\" : 2\n },\n {\n \"b\" : 2,\n \"a\" : 8\n },\n {\n \"b\" : 9,\n \"a\" : 7\n },\n {\n \"b\" : 3,\n \"a\" : 6\n }\n ],\n \"operation\" : \"+\"\n}",
"reward": "1.00",
"sched": "2018-04-19T15:54:24.657644+08:00",
"parent": "shit",
"type": "homework",
"child": "",
"occurrence": {
"name": "once"
},
"status": {
"name": "ongoing"
},
"date_created": "2018-04-26T10:13:42.913149+08:00",
"date_modified": "2018-04-26T10:13:42.953485+08:00"
}
]
код при получении данных
// здесь я хочу получить только данные из dapi, имя статуса! = "static"
и добавьте его в getalldetail, который является переменной getAllDetail: [[String: Any]] = [String: Any]
func demoApi() {
Alamofire.request("test.api", method: .get, parameters: nil, encoding: JSONEncoding.default, headers: nil).responseJSON { (response:DataResponse<Any>) in
switch(response.result) {
case .success(_):
guard let json = response.result.value as! [[String:Any]]? else{ return}
print("Api Response : \(json)")
// here i only want to get data from the dapi which status name != "static"
for item in json {
self.getAllDetail.append(item)
}
if !self.getAllDetail.isEmpty{
DispatchQueue.main.async {
self.tableView.reloadData()
}
}
break
case .failure(_):
print("Error")
break
}
}
}