我创建了这个脚本,想问一下如何将JSON决定的日期获取到另一个视图中?
let url = URL(string: "http://192.168.178.26/iso/loginserv.php")
guard let requestUrl = url else { fatalError() }
var request = URLRequest(url: requestUrl)
request.httpMethod = "POST"
let postString = "user=\(self.user)&pass=\(self.pass)";
request.httpBody = postString.data(using: String.Encoding.utf8);
let task = URLSession.shared.dataTask(with: request) {
(data, response, error) in
if let error = error {
print("Error took place \(error)")
return
}
guard let data = data else {return}
do{
let users = try JSONDecoder().decode(User.self, from: data)
print("Response data Name: \n \(users.Name)")
if !(data.isEmpty) {
self.signedIn = true
}
}catch let jsonErr{
print(jsonErr)
}
}
task.resume()
对于JSON解码的数据,我的意思是/(users.Name)变量...