gpt4 book ai didi

android - 在 key firebase 中获取 key

转载 作者:搜寻专家 更新时间:2023-11-01 08:28:44 25 4
gpt4 key购买 nike

我的 firebase 数据库中以以下格式存储了客户数据。

{
"fEYfwd8p9oSGAF6iUtXDLkMBCqc2" : { //user id
"-KdLAGG-8VOMd62Noyc8" : { //customer id
"customerCode" : "shi",
"customerLimit" : "2569",
"customerName" : "Shishir"
},
"-KdOraGISFJ6epjWucfh" : { //customer id
//other cust details
}
},
"jxW41BgSNWdRPyWtUkZA2G0eLhf2" : { //user id
"-KdCgJKh6_Rb8MOi-fIj" : {
"customerCode" : "Kau",
"customerLimit" : "800",
"customerName" : "Kaushik"
},
"-KdCgacTYBkThnVWe4sb" : {
//other cust details
},
"-KdCggxld52mq0DsGRjH" : {
//other cust details
},
"-KdChbdoV7nxwZoGLWsY" : {
//other cust details
}
}
}

在我的 android 应用程序中,我试图在为客户创建其他详细信息之前检查客户代码是否存在,下面是我的做法。

DatabaseReference dbRef=FirebaseDatabase.getInstance().getReference("customers")
.child(FirebaseAuth.getInstance().getCurrentUser().getUid());
dbRef.orderByChild("customerCode").equalTo(code).addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot snapshot) {
if (!snapshot.exists()) {
editTextAC.setText("");
editTextAC.setError("Customer code not found in database.");
} else {
//need to get customer id here.
}
}
@Override
public void onCancelled(DatabaseError dbError) {
Toast.makeText(activity, dbError.getMessage(), Toast.LENGTH_SHORT).show();
}
});

我正在获取以下格式的快照数据。

{
key = jxW41BgSNWasdsaRPsdyaWtUkZA2G0eLhf2,
value = {-KdChbdoV7nfdasxwZoGLWsY = {
customerCode = Ses,
customerLimit = 78888,
customerName = Sheshu
}
}
}

我需要从上面的 value 中获取客户 ID。我尝试执行 snapshot.getKey() 检索第一级 keyjxW41BgSNWasdsaRPsdyaWtUkZA2G0eLhf2 当我说 snapshot.getValue() 将检索 value 作为字符串。我如何从上面获取客户 ID?

最佳答案

for (DataSnapshot child : snapshot.getChildren()) {
Log.i("TAG", "child key = " + child.getKey());
}

关于android - 在 key firebase 中获取 key,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42431858/

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