【发布时间】:2020-09-09 03:46:38
【问题描述】:
我有一些代码可以存储特定操作系统在 Firebase 上的投票次数。我使用以下内容来存储它:
DatabaseReference windowsChoice;
在 onCreate 方法内部:
FirebaseDatabase.getInstance().getReference("Windows");
在按钮方法中,我将数据存储到 firebase:
String id = "TimesClicked";
windowsChoice.child(id).setValue(b); //b holds the amount of times that Windows has been clicked
生成的格式是这样的:
{"Windows":{"TimesClicked":8},"choice1Num":23} // ignore choice1Num
以下代码将为我获取 Windows (TimesClicked:8) 的值:
String result = new Connector().execute().get();
JSONObject ob = new JSONObject(result);
String jsonString = ob.getString("Windows");
String id = "TimesClicked";
windowsChoice.child(id).setValue(b);
intent.putExtra("result", jsonString);
startActivity(intent);
但是我怎样才能得到 TimesClicked 标签的值呢?
【问题讨论】:
标签: java android json firebase firebase-realtime-database