我想从这些阵列获取状态和消息。 我不知道如何映射。
[<null>, {
message = "Not matched";
status = 400;
}]
这是我的代码
class QRScanValidAPIMapper: NSObject {
var message: String!
var status: Int!
init(_ rawData: Any) {
print(rawData)
let data = rawData as? Dictionary<String,Any>
self.message = data?["message"] == nil ? rawData as! String : data?["message"] as! String
self.status = data?["status"] == nil ? 0 : data?["status"] as! Int
}
}
答案 0 :(得分:1)
从failure
获取Array
字典并从中获取值。像这样-
let array = [nil, ["message" : "Not matched", "status" : 400]]
for response in array {
if let failureResponse = response {
print(failureResponse["message"]!)
print(failureResponse["status"]!)
}
}
让我知道您是否仍然有任何问题。