Android访问带有钥匙的Firebase,其中包含空格 [英] Android access Firebase with Keys with spaces in them

查看:99
本文介绍了Android访问带有钥匙的Firebase,其中包含空格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这可能是一个愚蠢的问题,但我无法找到谷歌的Firebase网站上的任何例子。如果我在First Name的firebase数据库中有一个键,然后我打电话给

  FirstNameClass firstName = dataSnapshot.getValue(FirstNameClass.class); 

FireNameClass {
Private String FirstName;
FirstName(){
}
FirstName(String firstName){
this.FirstName = firstName;




$ b $ p $它会返回null,因为它试图映射到名字,而不是与空间的名字。有没有不同的方式来实现这一点,因为我所有的价值观都有空间在他们的设计,我愿意做额外的工作,以保持这种设计,如果可能的话。

解决方案

尝试使用 @PropertyName 。你的模型应该是这样的:

$ $ $ $ $ $ $ $
$ b $ Property $ Name
public String FirstName;
...
}




我没有尝试过。如果它不工作,我想我知道另一种方法来做到这一点,并将更新这个答案。


希望这有助于


This might be a dumb question but I couldn't find any examples on google's firebase site. If I have a key in the firebase database of "First Name" and then I call

FirstNameClass firstName = dataSnapshot.getValue(FirstNameClass.class);

FireNameClass{
    Private String FirstName;
    FirstName(){
    }
    FirstName(String firstName){
        this.FirstName = firstName;
    }
}

It'll return null because it's trying to map to FirstName instead of First Name with a space. Is there a different way to achieve this because all my values have spaces in them just by design and I am willing to do extra work to keep this design if possible.

解决方案

Try using @PropertyName. Your model should look like this:

FireNameClass{

    @PropertyName("First Name")
    public String FirstName;
    ...
}

Note: I haven't tried it. If it doesn't work, I think I know another way to do it and will update this answer

Hope this helps

这篇关于Android访问带有钥匙的Firebase,其中包含空格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆