gpt4 book ai didi

java - Android firebase getValue() 不工作

转载 作者:太空宇宙 更新时间:2023-11-04 12:23:57 24 4
gpt4 key购买 nike

我有以下 JSON 文件

{
"TestNode" : {
"TestKey" : "TestValue",
"TestKeyTwo" : "TestValueTwo"
},
"TestNode2" : {
"One" : {
"ItemOne" : "email@gmail.com",
"ItemTwo" : "zYMnPqefn7BlGDidpOocff6Xcg==\nBKb1sfaDdgfe0=\n1yVcV0mciIQXtAf/4LqGdDw==\n",
"ItemThree" : "name"
},
"Two" : {
"email" : "emailtwo@gmail.com",
"password" : "xFBvDPcnp/efebUhtefZ0+XMFfw==\ngAb5fSbzAefeQXc=\ng/WdCpusQl2umtPVOefefzjs1A==\n",
"username" : "othername"
}
}
}

监听器代码

TestNode.addListenerForSingleValueEvent(new ValueEventListener() {

@Override
public void onDataChange(DataSnapshot dataSnapshot) {

if(dataSnapshot.hasChild(TestKey)) {
String TestKeyString = TestNode.child(TestKey).getKey();
String TestValueString = TestNode.child(TestKey).getValue();
}
}

@Override
public void onCancelled(DatabaseError databaseError) {}
});

我收到错误

Cant resolve method getValue();

P.S 由于上述错误,我还没有运行代码

最佳答案

试试这个代码:

 TestNode.addListenerForSingleValueEvent(new ValueEventListener() {

@Override
public void onDataChange(DataSnapshot dataSnapshot) {
Log.d("TEST","key: "+dataSnapshot.getKey());
Log.d("TEST","value: "+dataSnapshot.getValue());
}

@Override
public void onCancelled(DatabaseError databaseError) {}
});

更新
尝试使用此代码只获取一个 child

 TestNode.orderByKey().equalTo(TestKey).addListenerForSingleValueEvent(new ValueEventListener() {

@Override
public void onDataChange(DataSnapshot dataSnapshot) {
Log.d("TEST","key: "+dataSnapshot.getKey());
Log.d("TEST","value: "+dataSnapshot.getValue());
}

@Override
public void onCancelled(DatabaseError databaseError) {}
});

关于java - Android firebase getValue() 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38553864/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com