1

I want to get the values from my Firebase json file At the moment i can add the values without any problem but i can't read it

i already tried multiple ways to loop it but i get always stuck

this is my json

{  
   "23ds1f5":{  
      "email":"email@example.com",
      "name":"my name",
      "points":0
   },
   "dsfv57s":{  
      "email":"email2@example.com",
      "name":"this name",
      "points":0
   },
   "r6s7gv98268":{  
      "email":"lol@example2.com",
      "name":"nameHere",
      "points":0
   }
}

the fields "23ds1f5" "dsfv57s" "r6s7gv98268" are auto generated and i want to get the email name and points values is that possible?

this is my code at the moment

FirebaseResponse response = await client.GetAsync("testing");
Data data = response.ResultAs<Data>();

            var json = response.Body;
            var firebaseLookup = JsonConvert.DeserializeObject<Data>(json);

            Console.WriteLine(json.ToString());


            var jsonObject = JObject.Parse(json);
            foreach (var tmp in jsonObject) {
                Console.WriteLine(tmp.Key);
            }

i don't know how to get the value i tried stuffs like this:

var dict = JsonConvert.DeserializeObject<Dictionary<string, string>>(json);
            foreach (var kv in dict) {
                Console.WriteLine(kv.Key + ":" + kv.Value);
            }

but no success

i would like to have the email from each

Update: with this code now i can take my 1st element, still i cant get the value

var jsonObject = JObject.Parse(json);
            foreach (var tmp in jsonObject) {
                Console.WriteLine(tmp);

            }

console:

[23ds1f5, {
  "email": "email@example.com",
  "name": "my name",
  "points": 0
}]

Problem Solved!!

            Dictionary<string, Data> elist = JsonConvert.DeserializeObject<Dictionary<string, Data>>(json);

            foreach (KeyValuePair<string, Data> entry in elist) {
                // do something with entry.Value or entry.Key
                //Console.WriteLine(entry.Key);
                Console.WriteLine(entry.Value.name);
                Console.WriteLine(entry.Value.email);
                Console.WriteLine(entry.Value.points);
            }
Youlle1934
  • 11
  • 2

0 Answers0