gpt4 book ai didi

ios - 过滤 JSON 数据并打印

转载 作者:行者123 更新时间:2023-11-28 10:55:07 26 4
gpt4 key购买 nike

我成功了parse JSON data在我的快速代码中,但我想打印具有特定值的代码。现在在代码中 vc.packages 打印所有但我只想打印那些:

  • “typeCode”为FULL,“validTo”有值,“stateCode”有效

我如何在我的代码中检查它并分别打印它?

func unzipPackage() {

let vc = storyboard?.instantiateViewController(withIdentifier: "LoadingScreenController") as! LoadingScreenController

let popup = STPopupController(rootViewController: vc)
popup.style = .formSheet
popup.hidesCloseButton = false
popup.navigationBarHidden = true
popup.backgroundView = UIVisualEffectView(effect: UIBlurEffect(style: .dark))
popup.containerView.layer.cornerRadius = 4
popup.present(in: self, completion: {

DemosClient.sharedInstance.requestDataPackage()
.then { response -> Void in

vc.contentSizeInPopup = CGSize(width: 600, height: 800)
vc.landscapeContentSizeInPopup = CGSize(width: 600, height: 800)


vc.titles = (self.parseJSON(response: response))
print(vc.titles)
vc.packages = response["results"] as? [[String:Any]] ?? []


print(vc.packages)

}
.catch { error in

print(error)
}

vc.loadData()
vc.startTimer()


})

最佳答案

为此你可以 filter你的results数组,然后分配 filter 的结果至 packages .

let results = response["results"] as? [[String:Any]] ?? []
vc.packages = results.filter {
return ($0["typeCode"] as? String == "FULL") &&
($0["validTo"] != nil) &&
($0["stateCode"] as? String == "valid")
}

关于ios - 过滤 JSON 数据并打印,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44110322/

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