gpt4 book ai didi

arrays - 如何快速从数组中获取对象

转载 作者:行者123 更新时间:2023-11-28 05:44:20 24 4
gpt4 key购买 nike

我想从这些数组中获取状态和消息。我不知道如何映射。

[<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
}
}

最佳答案

Array 中获取failure 字典并从中获取值。像这样 -

let array = [nil, ["message" : "Not matched", "status" : 400]]

for response in array {

if let failureResponse = response {

print(failureResponse["message"]!)
print(failureResponse["status"]!)
}
}

如果您还有任何问题,请告诉我。

关于arrays - 如何快速从数组中获取对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55448042/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com