none
Json serilestirme dynamickey RRS feed

  • Genel Tartışma

  • Merhabalar,
    textboxta grafik degerlerini girip json olarak kaydetmek istiyorum.Burda textboxtan 1. grafigi girip 
    kaydettikten sonra ikinci kez grafik olusturmak istersem Jsonda  grafik1 grafik2 seklinde numaralandirmak istiyorum.
    Kodlarim ve olusan json asagidaki gibi;
     public class Example
            {
                public LineChart Linechart { get; set; }
            }
            
            Example exa = new Example();
            string dir = AppDomain.CurrentDomain.BaseDirectory;
            string fileName = "Settings.json";
           
            private void button1_Click(object sender, EventArgs e)
            {
                listBox1.ClearSelected();
                exa.Linechart = LineChart.getLineChart();
                
                // Read existing json data
                var fileName = dir +"Settings.json";
                
                var jsonData = System.IO.File.ReadAllText(fileName);
                // De-serialize to object or create new list
                var employeeList = JsonConvert.DeserializeObject<List<Example>>(jsonData)
                                      ?? new List<Example>();
                employeeList.Add(exa);
                
                // Update json data string
                jsonData = JsonConvert.SerializeObject(employeeList, Formatting.Indented);
                System.IO.File.WriteAllText(fileName, jsonData);
                
            }
    
    
    public class LineChart 
        {
            public string MaxDatapoint { get; set; }
            public string ChartBackgroundColor { get; set; }
            public string ChartTitle { get; set; }
            public string ChartTitleColor { get; set; }
            public string chartDataMarkerShowlabel { get; set; }
            public static LineChart getLineChart()
            {
                LineChart linechart = new LineChart();
                Form1 form = Application.OpenForms[0] as Form1;
    
                linechart.MaxDatapoint = form.MaxDPtxt_line.Text;
                linechart.chartDataMarkerShowlabel = form.DMarkertxt_line.Text;
                linechart.ChartBackgroundColor = form.BGColortxt_line.Text;
                linechart.ChartTitle = form.Titletxt_line.Text;
                linechart.ChartTitleColor = form.TColortxt_line.Text;
                
                return linechart;
            }

    olusan JSON ;
    [
      {
        "Linechart": {
          "MaxDatapoint": "10",
          "ChartBackgroundColor": "red",
          "chartDataMarkerShowlabel": "true",
          "ChartTitle": "xy",
          "ChartTitleColor": "blue",
        }
      },
      {
        "Linechart": {
          "MaxDatapoint": "15",
          "ChartBackgroundColor": "yellow",
          "chartDataMarkerShowlabel": "true",
          "ChartTitle": "",
          "ChartTitleColor": "blue",
        }
      }
    ]
    
    istedigim JSON ise asagidaki gibi:
      {
        "Linechart1": {
          "MaxDatapoint": "10",
          "ChartBackgroundColor": "red",
    	  "chartDataMarkerShowlabel": "true",
          "ChartTitle": "xy",
          "ChartTitleColor": "blue",
        },
      "Linechart2": {
          "MaxDatapoint": "15",
          "ChartBackgroundColor": "red",
          "chartDataMarkerShowlabel": "true",
          "ChartTitle": "xy",
          "ChartTitleColor": "blue",
        }

    Numaralandirmayi nasil yapabilirim ve su fazladan olan parantezlerin bi önemi varmi?Simdiden sagolun

    16 Mayıs 2018 Çarşamba 21:22