检查密钥是否存在firebase Android [英] check if a key exist firebase Android
本文介绍了检查密钥是否存在firebase Android的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我要检查Firebase数据库中是否存在密钥.因此,例如,我要查找键"upvotes"以查看其是否存在.
I want to check if a key exist in the firebase db. so for example, I want to look for the key "upvotes" to see if it exist or not.
这是一个范例,此处不存在"upvotes"键:
Here is an exmaple, "upvotes" key does not exist in here:
现在,我尝试检查键"upvotes"是否在此位置:
Now I my attempt to check if the key "upvotes" is at this location:
Map<String, Object> newPost = (Map<String, Object>) ids.next().getValue();
if(newPost.get("upvotes").toString().equals("upvotes")){
disp_rate = newPost.get("upvotes").toString();
}
else
{
disp_rate = "0";
}
我的尝试是错误的,所以如何检查此位置是否存在键"upvotes".
My attempt is wrong, so how do I check if the key "upvotes" exist at this location.
推荐答案
只需使用此布尔函数containsKey
所以...
boolean check_rate = newPost.containsKey("upvotes");
if(check_rate == true){
String disp_rate = newPost.get("upvotes").toString();
rate_count.setText(disp_rate);
}
else{
System.out.println("FAILED");
}
如果有人在投票方面存在相同问题,这将解决交易.
This will fix the transaction if anyone is having the same issue with upvotes.
这篇关于检查密钥是否存在firebase Android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文