在我的应用程序中,我使用firebase,我将主要用户数据保存在行中,并在字典中保存重要(特征)。用户可以添加,修改和删除数据。有几次我从数据库中获得了成功的数据,但由于某种原因我得到了一个字典而不是一个数组。而且,这个数组包含对象NSNull应用程序和fall。这是我检索数据的代码:
[self.ref observeEventType:FIRDataEventTypeValue withBlock:^(FIRDataSnapshot * _Nonnull snapshot) {
TSFireUser *user = [[TSFireUser alloc] init];
NSString *token = [[NSUserDefaults standardUserDefaults] valueForKey:@"token"];
FIRUser *fireUser = [FIRAuth auth].currentUser;
NSString *key = [NSString stringWithFormat:@"dataBase/users/%@/userData", fireUser.uid];
NSString *keyToParameters = [NSString stringWithFormat:@"dataBase/users/%@", fireUser.uid];
FIRDataSnapshot *fireUser = [snapshot childSnapshotForPath:key];
FIRDataSnapshot *fireUserParameters = [snapshot childSnapshotForPath:keyToParameters];
FIRDataSnapshot *userIdent = fireUser.value[@"userID"];
FIRDataSnapshot *userName = fireUser.value[@"displayName"];
FIRDataSnapshot *userEmail = fireUser.value[@"email"];
FIRDataSnapshot *userPhoto = fireUser.value[@"photoURL"];
FIRDataSnapshot *dateOfBirth = fireUser.value[@"dateOfBirth"];
FIRDataSnapshot *location = fireUser.value[@"location"];
FIRDataSnapshot *gender = fireUser.value[@"gender"];
FIRDataSnapshot *parameters = fireUserParameters.value[@"parameters"];
user.uid = (NSString *)userIdent;
user.displayName = (NSString *)userName;
user.email = (NSString *)userEmail;
user.photoURL = (NSString *)userPhoto;
user.dateOfBirth = (NSString *)dateOfBirth;
user.location = (NSString *)location;
user.gender = (NSString *)gender;
user.parameters = (NSMutableDictionary *)parameters;}];
我将不胜感激任何帮助
答案 0 :(得分:1)
我独自决定了这个问题。最重要的是,数据库中数据的键以行号@" 1",@" 2",@" 3"通过添加单词" key"一切都运作良好。结果,键看起来像这样:@" key1",@" key2" @" key3" ..