Hi everyone...
I have been doing queries to database and I get an array of json with String format, and I need to convert (downcasting) to Array or Dictionary to create a TableView with the data got previously
func closeTaskService(_ valor: String, completionHandler: (_ response:NSString) -> ()) {
let request = NSMutableURLRequest(url: URL(string: "http:/
let db = self.dato.object(forKey: "dbName")
let db1 = db as AnyObject? as? String
let dbName : String = (db1 as AnyObject? as? String)!
request.httpMethod = "POST"
let postParams = "DB_name="+dbName+"&"+"valor=%"+valor+"%"
/
request.httpBody = postParams.data(using: String.Encoding.utf8)
let task = URLSession.shared.dataTask(with: request as URLRequest) {
(data, response, error ) in
/
let responseString: String = String (data: data!, encoding: String.Encoding(rawValue: String.Encoding.utf8.rawValue))!
/
let numbers = responseString.replacingOccurrences(of: "[", with: "", options: .literal, range: nil)
let numbers2 = numbers.replacingOccurrences(of: "]", with: "", options: .literal, range: nil)
/
/
let myArray : [String] = numbers2.components(separatedBy: "},{")
print(myArray)
for array in myArray{
print(array)
print(myArray[1])
}
}
task.resume()
}