getObjectInBackgroundWithId

getObjectInBackgroundWithId

首先,我得到当前用户和该用户的关联书(这是指向书objectId的指针)。然后,我想使用getobjectinBackgroundWithId方法查找书,然后显示书名。当我将getObjectInBackgroundWithId:storeUserID更改为getObjectInBackgroundWithId:@"f4Dg92xC2"时,它可以完美运行!

PFUser *currentuser = [PFUser currentUser];
storeUserID = currentuser[@"connectedBook"]; //Store book id in a string
NSLog(@"%@", storeUserID); // what i get <Book:f4Dg92xC2:(null)>


PFQuery *query = [PFQuery queryWithClassName:@"Book"];
[query getObjectInBackgroundWithId:storeUserID block:^(PFObject *books, NSError *error){
    PFObject *bookObject = books[@"bookName"];
    NSLog(@"bookName:%@", bookObject);
}];

当我运行此命令时,带有书名的NSLog显示:

错误:特殊键错误:objectId(代码:102,版本:1.2.20)
2014-09-17 23:28:56.529 MyApp [18977:90b] bookName :(空)

在此先多谢!!

最佳答案

您的评论//Store book id in a string不正确。指针不返回字符串对象ID,而是返回对象本身。因此,您已经拥有了它,无需调用getObjectInBackgroundWithId:

日志<Book:f4Dg92xC2:(null)>甚至告诉您它是Book实例(而不是NSString实例)。

10-08 17:05