我在 iOS 应用程序中使用 parse.com 将数据存储到解析云服务。我在查询嵌套对象时遇到问题。我有以下数据模型:
“游戏”类
包含“获奖者”
“获胜者”是一个数组NSDictionary
,字典中的每一项都是 1 Player 到 N Powers 的映射
playerPowers 值是对象数组(目前权力只有一个名称)键:对象ID玩家的 (PFObject)
对于每个获奖者,我都会在“获奖者”(可以有多个获奖者)中添加一个NSDictionary
对象,就像这样:
NSDictionary * winnerWithPowers = [NSDictionary dictionaryWithObject:tempPowers
forKey:[aWinnerPFObject objectId]];
[newGame addObject:winnerWithPowers forKey:@"winners"];
对于字典中的每个项目,键是玩家的现有 objectId,值是数组PFObjects
(权力)也在服务器上。当我查询“获胜者”时我想检索all填充的数据、所有获胜者及其各自的权力PFObjects
以及他们所有的数据。当我查询“获胜者”时,每个权力的详细信息PFObject
不完整(key:name 的值为 null)。以下是查询,然后是打印结果的代码,最后是包含两个获胜者的字典的输出:
// In 视图将出现:
PFQuery * gamesQuery = [PFQuery queryWithClassName:@"Game"];
[gamesQuery orderByDescending:@"createdAt"];
[gamesQuery findObjectsInBackgroundWithBlock:^(NSArray * theGames, NSError * error) {
if (error) {
NSLog(@"ERROR: There was an error with the Query for Games!");
} else {
_gamesPF = [[NSMutableArray alloc] initWithArray:theGames];
[_tableView reloadData];
}
}];
// 在表格视图中cellForRowAtIndexPath:方法(这是我自己的TableViewController)
NSArray * testArray = [[_gamesPF objectAtIndex:row] objectForKey:@"winners"];
if ([testArray count] > 0) {
// print contents of first dictionary winners entry
NSLog(@"TestDictfromPF %@", [testArray objectAtIndex:0]);
}
Log:
2013-01-18 09:42:26.430 GamesTourney[20972:19d03] TestDictfromPF {
jchtlqsuIY = (
"<Power:OlJfby1iuz:(null)> {\n}", // problem is {\n}. Data exists on server but not in local structure after query
"<Power:eQkMUThGOh:(null)> {\n}" // ditto
);
}