我有这样的JSON。
livefeeds= {
"-KTn8pbqFHBUvgJ1Gwyl" = {
category = Alerts;
text = "Samsung Galaxy Note 7 owners told to turn off device";
timestamp = 1476179485648;
"user_id" = V7EFBV6uATf8urLXX9eK4EHhxmG2;
};
"-KTn8pbrhHyNzeLh2vOq" = {
category = News;
text = "Chicago Teachers Union, school board reach tentative contract agreement";
timestamp = 1476179485648;
"user_id" = V7EFBV6uATf8urLXX9eK4EHhxmG2;
};
}
我需要根据键category
进行查询。
例如:如果我只想要提醒,它应该只检索等于"警报"的类别值。仅数据。
以下是检索livefeeds
的查询。
[[self.ref queryOrderedByChild:@"livefeeds"] observeEventType:FIRDataEventTypeValue withBlock:^(FIRDataSnapshot * _Nonnull snapshot) {
NSLog(@"---> %@",snapshot.value);
}];
答案 0 :(得分:6)
首先直到孩子“livefeeds”然后“queryOrderedByChild”类别并像这样使用equal to
孩子
[[[[self.ref child:@"livefeeds"] queryOrderedByChild:@"category"]
queryEqualToValue:groupId]
observeEventType:FIRDataEventTypeValue withBlock:^(FIRDataSnapshot * _Nonnull snapshot) {
if (snapshot.value != [NSNull null]){
for (NSDictionary *snap in [snapshot.value allValues]) {
NSLog(@"---> %@",snap);
}
}
}];