gpt4 book ai didi

ios - 从对象中解析特定字段

转载 作者:行者123 更新时间:2023-11-29 01:39:59 24 4
gpt4 key购买 nike

我正在尝试从 objects 中提取 prayerRequest。但是,我不确定如何完成此操作。

var allPrayerRequests = [""]

override func viewDidLoad() {
super.viewDidLoad()
var query = PFQuery(className: "PrayerRequests")
query.findObjectsInBackgroundWithBlock({ (objects, error) -> Void in
if error == nil {
if let objects = objects as? [PFObject] {
for object in objects {
println(object)
}
}
}
})
}

如果我这样做,println(object),我会得到以下输出:

<PrayerRequests: 0x7feec8eec7f0, objectId: jy2KwGXenC, localId: (null)> {
ACL = "<PFACL: 0x7feec8eca220>";
prayerRequest = qoiejr;
}
<PrayerRequests: 0x7feec8eed9a0, objectId: KxMpxyWV0P, localId: (null)> {
ACL = "<PFACL: 0x7feec8eed600>";
prayerRequest = qwer;
}
<PrayerRequests: 0x7feec8eee5f0, objectId: DRHBwJpq16, localId: (null)> {
ACL = "<PFACL: 0x7feec8eee840>";
prayerRequest = zxcv;
}
<PrayerRequests: 0x7feec8eeecd0, objectId: cOOdOyv4TM, localId: (null)> {
ACL = "<PFACL: 0x7feec8eeef10>";
prayerRequest = oijg;
}
<PrayerRequests: 0x7feec8eef3c0, objectId: bmO3oVKUDG, localId: (null)> {
ACL = "<PFACL: 0x7feec8eef680>";
prayerRequest = asdf;
}
<PrayerRequests: 0x7feec8eef800, objectId: RcR3wbbMYv, localId: (null)> {
ACL = "<PFACL: 0x7feec8eefda0>";
prayerRequest = qwer;
}

因此,正如您在代码中看到的那样,有一个带有 prayerRequest 的字段。我希望能够提取这个字段,就像我要执行 println(object.objectId) 一样,它将以下内容输出到控制台:

Optional("jy2KwGXenC")
Optional("KxMpxyWV0P")
Optional("DRHBwJpq16")
Optional("cOOdOyv4TM")
Optional("bmO3oVKUDG")
Optional("RcR3wbbMYv")

但只有 prayerRequest 字段。任何人都有办法实现这一目标吗?

最佳答案

PFObject 包含 JSON 兼容数据的键值对。要获得任何值,您需要使用 objectForKey

所以你可以将它提取为 -

object.objectForKey("prayerRequest")

关于ios - 从对象中解析特定字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32516245/

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