你一般不会存放喜欢你的根节点下是正确的数据 - 这通常是根节点下保存一个子节点(S) ,如下所示:
sizzling-inferno-255
book_node_0
author: test_author
title: test title
book_node_1
author: another author
title: another title title
Firebase *ref = [[Firebase alloc] initWithUrl: @"sizzling-inferno-255"];
[ref observeEventType:FEventTypeChildAdded withBlock:^(FDataSnapshot *snapshot) {
NSLog(@"%@", snapshot.value[@"author"]);
NSLog(@"%@", snapshot.value[@"title"]);
}];
将迭代每个书籍节点并返回该节点的快照。所以第一次返回一个快照,这将是
book_node_0
author: test_author
title: test title
并返回快照第二时间将是
book_node_1
author: another author
title: another title title
的book_node密钥与childByAutoId生成。
ChildAdded逐个读取每个子节点中的一个作为快照。
值读入节点中的所有内容;所有的孩子节点,那些孩子等等,并且可以是大量的数据。如果裁判节点包含的孩子,像这样的答案,所有的节点都回来了,他们需要遍历得到孩子的数据,所以内部的观察块...
for child in snapshot.children {
NSLog(@"%@", child.value[@"author"]);
}
编辑 - 和具体回答OP的问题,这里是你如何与火力地堡结构问题做:
self.myRootRef = [[Firebase alloc] initWithUrl:@"https://**********"];
[ref observeEventType:FEventTypeChildAdded withBlock:^(FDataSnapshot *snapshot) {
NSString *key = snapshot.key;
NSString *value = snapshot.value;
if ([key isEqualToString:@"author"]) {
NSLog(@"author = %@", value);
} else if ([snapshot.key isEqualToString:@"title"]) {
NSLog(@"title = %@", value);
}
}];
来源
2016-05-16 19:17:06
Jay
检查,如果你的火力网址正确 – Rajesh
FEventTypeChildAdded是完全合法的 - 它会在遍历每个子节点加载孩子们在一个一次。我测试了它,并且他的代码正常工作。也许你的firebase url不对,或者你有规则防止数据被读取?什么路线崩溃? – Jay
让我补充说,它完美的工作假设这不是根参考。如果是,请参阅我的答案。 – Jay