【发布时间】:2020-09-21 17:51:17
【问题描述】:
我制作了一个小型网站,供家人和朋友猜测我们下一个宝宝的姓名、性别、出生日期等。我将 vue 与 firebase 的实时数据库结合使用。 现在我想用 c# 编写一个控制台应用程序来验证所有的赌注并指出一个赢家。 问题是我设置数据库的方式:
-Users
-Davy vettorato
-posts
-M5HuYYaUuKgqpD9qdVT
date: "2020-09-23"
gender: "Meisje"
weight: "2550"
length: "52"
name: "Nele"
extra_question: "11:00"
-Dries
-posts
-MAerWe2LjQHGM6vEVur
date: "21/9/2020"
gender: "Meisje"
weight: "4,200"
length: "55"
name: "Elise"
extra_question: "11:45"
-MAerhMgLbAe_sUyg5AE
date: "21/9/2020"
gender: "Jongen"
weight: "4,200"
length: "55"
name: "Thibaut"
extra_question: "11:46"
我能够获得每个用户,但后来我卡住了。我想为从数据库派生的每个用户投注对象。这就是我已经开始的事情了
IFirebaseConfig config = new FirebaseConfig
{
AuthSecret = "//",
BasePath = "https://babyproject-fb0.firebaseio.com/"
};
IFirebaseClient client = new FireSharp.FirebaseClient(config);
if (client != null)
{
Console.WriteLine("Connected");
}
FirebaseResponse response = client.Get("");
var json = response.Body;
var result = JObject.Parse(json);
有谁知道我如何获得每个用户的所有单独投注?我已经尝试使用 selectTokens,但没有任何成功..
【问题讨论】:
-
我希望像
client.Get("User")这样的东西,然后你必须遍历JObject.ChildrenTokens:newtonsoft.com/json/help/html/… 或Descendants列表:newtonsoft.com/json/help/html/… -
感谢您的回答。我用 .children 方法解决了这个问题。然后我可以将用户作为 JProperty。我已将所有用户放在一个列表中,用于构建我的下一条路径。这种方法再次帮助我在嵌套 json 中走得更远。
标签: c# vue.js firebase-realtime-database fire-sharp