任何人都可以帮助我从下面的API响应中获取“数据”的值。这是GraphQL API响应
["data": {
signin = {
result = {
firstName = evol;
lastName = adc;
profileImage = "http:/xxx.com/public/static/default.jpg";
status = "<null>";
token = "eyxxx";
};
};
}]
答案 0 :(得分:0)
您可以从API响应中获取数据值,
let json = try JSONSerialization.jsonObject(with: data, options: .allowFragments)as? [String : Any]
print("Json",json!)
let jsonUnwrapped = json.unsafelyUnwrapped
let jsonData = jsonUnwrapped["data"]as? [String : Any]
print("data....", jsonData!)
if let signup = jsonData.unsafelyUnwrapped as? [String : Any]
{
let signupDetails = signup["signin"]as? [String : Any]
if signupDetails?.count == 0 || signupDetails == nil
{
let error = jsonUnwrapped["errors"]
print("error.....",error! )
DispatchQueue.main.async {
self.view.makeToast("Invalid credentials", duration: 0.5, position: .bottom)
}
}
else
{
DispatchQueue.main.async {
//Your code here...
}
}