let responseString = String(data: data, encoding: .utf8)
if responseString["is_valid"] == true {
print("Login Successful")
} else {
print("Login attempt failed")
}
我試圖從responseString
字典中獲取"is_valid"
的值。但是,我不知道如何。我試過的所有東西都失敗了。如何從Swift3/Swift4中的JSON獲取bool的值?
responseString
看起來是這樣的,當通過print()
輸出:在data
與JSONSerialization
if let responseString = try? JSONSerialization.jsonObject(with: data, options: []) as? [String: Bool] {
if responseString!["is_valid"] == true {
print("Login Successful")
} else {
print("Login attempt failed")
}
}
作品。非常感謝! – Sanjay