{-KVsGKFs_VfPKYNylmH0={entryDate=11/14/2016, markerColor=30, daysSick=2, userId=ABCD, sickness=Flu, severity=Medium, longitude=-75.57221984863281, latitude=38.38811111450195, type=Viral},
15fKhOQizabN0EL6ZAq7SOk3Gqb2={entryDate=11/8/2016, markerColor=210, daysSick=5, userId=15fKhOQizabN0EL6ZAq7SOk3Gqb2, sickness=Pneumonia, severity=High, longitude=-77.1867304, latitude=38.80375897, type=Bacterial},
2SfN7GkHsjXHFuGGYQJAQoRCOho1={-KXLF4gT9wUfvgRuYxWI={entryDate=11/24/2016, markerColor=210, daysSick=3, userId=2SfN7GkHsjXHFuGGYQJAQoRCOho1, sickness=Anthrax, severity=Medium, longitude=0, latitude=0, type=Bacterial}}
对于以上json响应,我必须检索“疾病”的所有关键值的数据。如何检索?
答案 0 :(得分:1)
以下代码可以帮助您从数据库中获取所有键值...这里BTChild详细信息是POJO类
databaseRef.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot snapshot) {
BTLog.d(TAG, "There are " + snapshot.getChildrenCount() + " blog posts");
for (DataSnapshot postSnapshot : snapshot.getChildren()) {
BTChildDetails post =postSnapshot.getValue(BTChildDetails.class);
BTChildDetails btChildDetails = new BTChildDetails(post.getName(), post.getId(), false);
childList.add(childDetails);
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
BTLog.d(TAG, "The read failed: ");
}
});