Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // 3251692 @ Pantip
- using System;
- using System.Collections.Generic;
- using System.Data;
- using System.Linq;
- using System.Windows.Forms;
- using FireSharp;
- using FireSharp.Config;
- using FireSharp.Interfaces;
- using FireSharp.Response;
- using Newtonsoft.Json.Linq;
- namespace FireSharpPantip_gaka
- {
- public partial class FrmGaka : Form
- {
- IFirebaseConfig config = new FirebaseConfig {
- AuthSecret = "your_firebase_secret",
- // เปิดเป็น Test Mode
- BasePath = "https://pantip-gaka.firebaseio.com/"
- };
- List<string> DName = new List<string>();
- List<string> DValue = new List<string>();
- List<string> DPath = new List<string>();
- public FrmGaka()
- {
- InitializeComponent();
- }
- //ถ้าต้องการใช้คลาส ลบการประกาศ List<string> ทั้งสามด้านบน แล้วเปลี่ยนด้านล่าง
- // DName => data.Name
- // DValue => data.Value
- // DPath => data.Path
- //และ uncomment คลาส ValueCollection บรรทัด 33,99-104
- //ValueCollection data = new ValueCollection();
- private void FrmGaka_Load(object sender, EventArgs e)
- {
- IFirebaseClient client = new FirebaseClient(config);
- FirebaseResponse response = client.Get("");
- JObject o = JObject.Parse(response.Body);
- AddValtoList(o);
- string checkdata = "";
- for (int i = 0; i < DName.Count; i++)
- {
- checkdata += String.Format("{0}. {1} : {2} ({3})\n", i+1, DName[i], DValue[i], DPath[i]);
- }
- MessageBox.Show(checkdata);
- }
- private void AddVal(string n, string v, string p)
- {
- DName.Add(n);
- DValue.Add(v);
- DPath.Add(p);
- }
- private void AddValtoList(JObject o)
- {
- List<string> l1 = o.Properties().Select(p => p.Name).ToList();
- foreach (string n1 in l1)
- {
- //List<string> l3 = ((JObject)o[n1]["Task"]).Properties().Select(p => p.Name).ToList();
- foreach (JProperty n3 in o[n1]["Task"])
- {
- foreach (JProperty n4 in o[n1]["Task"][n3.Name])
- {
- foreach (JProperty n5 in o[n1]["Task"][n3.Name][n4.Name])
- {
- if (n5.Value.Type.ToString() != "String")
- {
- foreach (JProperty n6 in o[n1]["Task"][n3.Name][n4.Name][n5.Name])
- {
- if (n6.Value.Type.ToString() != "String")
- {
- foreach (JProperty n7 in o[n1]["Task"][n3.Name][n4.Name][n5.Name][n6.Name])
- {
- AddVal(n7.Name, (string)n7.Value, n7.Path);
- }
- }
- else
- {
- AddVal(n6.Name, (string)n6.Value, n6.Path);
- }
- }
- }
- else
- {
- AddVal(n5.Name, (string)n5.Value, n5.Path);
- }
- }
- }
- }
- }
- }
- }
- //class ValueCollection
- //{
- // public List<string> Name { get; set; } = new List<string>();
- // public List<string> Value { get; set; } = new List<string>();
- // public List<string> Path { get; set; } = new List<string>();
- //}
- }
Advertisement
Add Comment
Please, Sign In to add comment