Есть много проблем с вашим кодом. Попробуйте и дайте мне знать, работает ли оно. Я также добавил объяснение сделанных мною изменений.
if let json = json { // The “if let” allows us to unwrap optional values safely only when there is a value, and if not, the code block will not run and jump to else statement
let message = json["message"] as? String ?? "" // The nil-coalescing operator (a ?? b) unwraps an optional a if it contains a value, or returns a default value b if a is nil.
if message == "success" {
DispatchQueue.main.async {
self.performSegue(withIdentifier: "homelogin", sender: self)
}
let id = json["id"] as? String ?? "" // String can directly be entered in double quotes. no need to use String()
let name = json["name"] as? String ?? ""
let username = json["username"] as? String ?? ""
let email = json["email"] as? String ?? ""
print("Emri " + name )
print("Emaili " + email )
print("Id " + id )
print("username " + username )
}else{
print("check your password or email")
}
} else {
print("Invalid json")
}