如何从 NSDictionary 获取关键数据 swift 4
How to get key data from NSDictionary swift 4
我想从 NSDictionary
得到结果 我从网络服务得到这个 NSDictionary
现在我想得到结果 .
我需要这个值"Your request is unsuccessfull. Please "
我试过这个 let ft = resultsm.value(forKeyPath: "Body.QR_FundTransferResponse.QR_FundTransferResult") as! String
但是存储数据并为所有请求打印相同的值
let result:NSDictionary = dict! as NSDictionary
The output is :
Body = {
"QR_FundTransferResponse" = {
"QR_FundTransferResult" = "Your request is unsuccessfull.
Please ";
};
};
假设你在一个函数中得到了这个并且结果是 [String: Any]
类型(例如字典):
guard let body = result["body"] as? [String: Any] else {
// Failed to find body, return empty string
return ""
}
guard let response = body["QR_FundTransferResponse"] as? [String: Any] else {
return ""
}
guard let result = response["QR_FundTransferResult"] as? String else {
return ""
}
// Now have "Your request is unsuccessful. Please "
return result
推荐您查看Codable
。
我想从 NSDictionary
得到结果 我从网络服务得到这个 NSDictionary
现在我想得到结果 .
我需要这个值"Your request is unsuccessfull. Please "
我试过这个 let ft = resultsm.value(forKeyPath: "Body.QR_FundTransferResponse.QR_FundTransferResult") as! String
但是存储数据并为所有请求打印相同的值
let result:NSDictionary = dict! as NSDictionary
The output is :
Body = {
"QR_FundTransferResponse" = {
"QR_FundTransferResult" = "Your request is unsuccessfull.
Please ";
};
};
假设你在一个函数中得到了这个并且结果是 [String: Any]
类型(例如字典):
guard let body = result["body"] as? [String: Any] else {
// Failed to find body, return empty string
return ""
}
guard let response = body["QR_FundTransferResponse"] as? [String: Any] else {
return ""
}
guard let result = response["QR_FundTransferResult"] as? String else {
return ""
}
// Now have "Your request is unsuccessful. Please "
return result
推荐您查看Codable
。