I am fetching the data from the JSON. I want to know how I can fetch the signal value. because as per the signal all the code will work.
["status": 200, "data": {"in_time" = "12:00 PM"; "out_time" = ""; signal = 01;}, "Message": Enable out time]
this is code which I am using: Here is all the data which I am using to get the json response
let parameters = ["emp_id": self.att_emp_id]
var request = URLRequest(url : url!)
request.httpMethod = "POST"
request.httpBody = try? JSONSerialization.data(withJSONObject:parameters, options: [])
request.addValue("application/json", forHTTPHeaderField: "Content-Type")
let session = URLSession.shared
session.dataTask(with: request, completionHandler: { (data, response, error) in
if let data = data {
do {
let json = try? JSONSerialization.jsonObject(with: data, options: []) as! Dictionary<String, Any>
if let json = json {
print("HERE SHOULD BE YOUR JSON viewdidAppear\(json)")
//var datas = [String:AnyObject]()
let status = json["status"] as? String
if let datas = json["data"] as? [String:AnyObject] , let in_time_Str = datas["in_time"] as? String, let out_time_Str = datas["out_time"] as? String , let grace_Str = datas["grace"] as? String , let signal_Str = datas["signal"] as? String
{
self.server_in_time = in_time_Str
self.server_out_time = out_time_Str
self.grace_str_time = grace_Str
self.sig_str = signal_Str
}
print("Signal : \(String(describing: self.sig_str))")
if status == "200" {
if self.server_in_time != "" {
print("Here is attendance IN TIME : \(self.server_in_time)")
}
if self.server_out_time != "" {
print("Here is attendance OUT TIME : \(self.server_out_time)")
}
if self.sig_str == "10" {
DispatchQueue.main.async {
self.out_time_button.isEnabled = false
}
} else if self.sig_str == "01" {
DispatchQueue.main.async {
self.inTimeTextField.text = self.server_in_time
self.in_time_button.isEnabled = false
self.out_time_button.isEnabled = true
}
} else if self.sig_str == "00" {
DispatchQueue.main.async {
self.inTimeTextField.text = self.server_in_time
self.outTimeTextField.text = self.server_out_time
self.in_time_button.isEnabled = false
self.out_time_button.isEnabled = false
}
}
} else {
print("Error : \(String(describing: error))")
}
}
}
} else {
print("Error \(String(describing: error?.localizedDescription))")
}
}).resume()