这是我在main中的代码,从firebase
中检索一组值 var jsonToSend = JsonConvert.SerializeObject(json, Formatting.None);
var multipart = new MultipartFormDataContent();
var body = new StringContent(jsonToSend, Encoding.UTF8, "application/json");
multipart.Add(body, "JsonDetails");
multipart.Add(new ByteArrayContent(System.IO.File.ReadAllBytes("E:\\file.png")), "DocumentDetails", "file1.png");
var httpClient = new HttpClient();
httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);
var response = httpClient.PostAsync(new Uri("uriToPost"), multipart).Result;
我必须检索arraylist天气中的所有值。图像显示了我的firebase,我必须遍历节点并获取子值:
答案 0 :(得分:0)
我希望你定义模型类构造函数,并在代码下面获取数据:
private DatabaseReference mDatabase;
private FirebaseDatabase mFirebaseInstance;
// put below two line in onCreate method.
mFirebaseInstance = FirebaseDatabase.getInstance();
mDatabase = mFirebaseInstance.getReference("usersDb/UserTable");
mDatabase.addValueEventListener(new ValueEventListener() { // here pass your firebase database instance..
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
weather.clear();
for (DataSnapshot postSnapshot: snapshot.getChildren()) {
model model = postSnapshot.getValue(model.class);
weather.add(model);
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});