小编Sou*_*rty的帖子

dataSnapshot.getChildren() 获取用户 ID,但不获取值

运行此代码时:

private void getData(DataSnapshot dataSnapshot) {
    for(DataSnapshot ds : dataSnapshot.getChildren()){
        Log.d(TAG, "UserID inside getData: "+userID);
        Log.d(TAG, "User Name inside getData: "+ds.child(userID).child("name").getValue());
        Log.d(TAG, "DS inside getData: "+ds.child(userID));

        hospitalCity = String.valueOf(ds.child(userID).child("city").getValue());
        Log.d(TAG, "User city inside getData: "+ds.child(userID).child("city").getValue());

        break;
    }
}
Run Code Online (Sandbox Code Playgroud)

日志显示了这一点:

getData 内的用户 ID:Lsncj8CIsfTQXc7E425AtLuDI5v2
getData 内的用户名:null getData 内的 DS:DataSnapshot { key = Lsncj8CIsfTQXc7E425AtLuDI5v2,value = null }

D/DonorList:getData 内的用户城市:null

这是数据库:

标题]

正如您所看到的,它获取了键,但是null尽管数据库显示其中包含值,但该值仍然存在。

java android firebase firebase-realtime-database

4
推荐指数
1
解决办法
8251
查看次数