我用了一个iOS应用parse.com来存储数据,以解析云服务。 我在与嵌套对象查询的麻烦。 我有以下数据模型:
类“游戏”中包含“赢家”
“赢家”是阵列NSDictionary
,字典中的每个产品1玩家与N权力的映射
playerPowers值是PFObjects数组 (权力只有一个名字目前) 关键:一个球员的OBJECTID(PFObject)
对于每一个赢家,我将添加到“赢家”(也可以是多个获奖者)一个NSDictionary
对象,就像这样:
NSDictionary * winnerWithPowers = [NSDictionary dictionaryWithObject:tempPowers
forKey:[aWinnerPFObject objectId]];
[newGame addObject:winnerWithPowers forKey:@"winners"];
为字典中的每个项目,关键是一个播放器的现有的ObjectID和的值是数组PFObjects
(功率)也在服务器上。 当我查询了“赢家”我想找回填充的所有数据,所有获奖者及其各自的权力PFObjects
他们所有的数据。 当我查询了“赢家”每个电源的细节PFObject
是不完整的(关键值:名称为空)。 下面是查询,那么,打印结果代码,接着通过含有两种中奖者的字典的输出:
//在viewWillAppear中:
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];
}
}];
//在tableview中的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]);
}
日志:
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
);
}