Graphql - 在 iOS 中获取数据
Graphql -Data fetching in iOS
任何人都请帮助我从下面得到 "data" 的值 API response.It 是那种 GraphQL API response
["data": {
signin = {
result = {
firstName = evol;
lastName = adc;
profileImage = "http:/xxx.com/public/static/default.jpg";
status = "<null>";
token = "eyxxx";
};
};
}]
您可以从 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...
}
}
任何人都请帮助我从下面得到 "data" 的值 API response.It 是那种 GraphQL API response
["data": {
signin = {
result = {
firstName = evol;
lastName = adc;
profileImage = "http:/xxx.com/public/static/default.jpg";
status = "<null>";
token = "eyxxx";
};
};
}]
您可以从 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...
}
}