0
curl -X PUT -d '{ "1": { "name": "Hauptbahnhof Berlin", "city": "Berlin"}, "2": { "name": "Hackerscher Markt", "city": "Berlin"}, "3": { "name": "Hauptbahnhof Frankfurt", "city": "Frankfurt"} }' 'https://xxx.firebaseio.com/stations.json'
結果第一項爲無效
它看起來像出口:
{
"stations" : [ null, {
"city" : "Berlin",
"name" : "Hauptbahnhof Berlin"
}, {
"city" : "Berlin",
"name" : "Hackerscher Markt"
}, {
"city" : "Frankfurt",
"name" : "Hauptbahnhof Frankfurt"
} ]
}
選擇數據有一個空值現在,爲什麼如此?
FirebaseDatabase database = FirebaseDatabase.getInstance();
DatabaseReference stationsRef = database.getReference("stations");
stationsRef.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
ArrayList<Map<String, String>> value = (ArrayList<Map<String, String>>) dataSnapshot.getValue();
Log.d(TAG, "Value is: " + value.toString());
}
@Override
public void onCancelled(DatabaseError error) {
// Failed to read value
Log.w(TAG, "Failed to read value.", error.toException());
}
});
=>值是:[NULL,{名稱=總站柏林,城市=柏林},{名稱= Hackerscher廣場,城市=柏林},{名稱=總站法蘭克福, 城市=法蘭克福} ]