我试图从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")