Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using Newtonsoft.Json;
- using Newtonsoft.Json.Linq;
- using System;
- using System.IO;
- using System.Windows.Forms;
- namespace IGEA
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- }
- private void Form1_Load(object sender, EventArgs e)
- {
- //Procitaj .json shemu
- string shema = File.ReadAllText("IGEA.schema.json");
- //Procitaj json
- JObject result = JObject.Parse(shema);
- //Za svaki input
- int id_polja = 0;
- foreach (var input in result["properties"])
- {
- //Za svaki element inputa (type, description)
- string tip, opis="";
- foreach (var a in input)
- {
- if (a["type"].ToString().Equals("array")) continue; //Onaj zadnji input preskacemo
- tip = a["type"].ToString();
- opis = a["description"].ToString();
- }
- TextBox tb = new TextBox();
- tb.Location = new System.Drawing.Point(180, (id_polja * 20) + 10);
- tb.Name = opis;
- tb.Width = 200;
- this.Controls.Add(tb);
- Label lb = new Label();
- lb.Text = opis;
- lb.Width = 200;
- lb.Location = new System.Drawing.Point(10, (id_polja * 20) + 10);
- this.Controls.Add(lb);
- id_polja++;
- }
- Button bt = new Button();
- bt.Text = "Spremi";
- bt.Location = new System.Drawing.Point(10, (id_polja * 20) + 10);
- bt.Click += new System.EventHandler(this.onClickEvent);
- this.Controls.Add(bt);
- }
- private void onClickEvent(object sender, EventArgs e)
- {
- dynamic jsonObject = new JObject();
- foreach (Control c in Controls)
- {
- if (c is TextBox) jsonObject[c.Name] = c.Text;
- }
- File.WriteAllText("studenti.json", JsonConvert.SerializeObject(jsonObject));
- MessageBox.Show("Spremljeno");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement