我试图获得' fname'来自我的Json,这是我的代码:
let httpResponse = response as? HTTPURLResponse
print(httpResponse!)
do {
let json = try JSONSerialization.jsonObject(with: data!, options: .mutableContainers)
DispatchQueue.main.async {
let Results = (json as! NSDictionary)
if (Results.value(forKey: "error") == nil) {
print(Results)
let x = Results.value(forKey: "user") as! NSDictionary
let fname= x.value(forKey: "fname")
print(fname!)
// self.userpass = ["username": self.usernametf.text!,"pass":self.passwordtf.text!]
// UserDefaults.standard.set(self.userpass, forKey: "userpass1")
}else{
print("wrong pass")
}
}
} catch {
print("error serializing JSON: \(error)")
}
这是我的Json:
{
status = 1;
user = "{\"id\":\"1\",\"fname\":\"\\u0645\\u0633\\u0639\\u0648\\u062f\",\"lname\":\"\\u0627\\u0645\\u0627\\u0645\\u06cc\\u0627\\u0646\",\"email\":\"smemamian@yahoo.com\",\"phone\":\"093666023695\",\"pass\":\"c4ca4238a0b923820dcc509a6f75849b\",\"bd\":\"1991-12-20\",\"byear\":\"1991\",\"bmonth\":\"12\",\"bday\":\"20\",\"img\":\"1480141509_1.png\",\"isdelete\":\"1\",\"current_date\":\"2016-11-09 10:04:36\"}";}
但我收到错误"Could not cast value of type '__NSCFString' (0x1012ec4a0) to 'NSDictionary' (0x1012ed288)."