H
HansvB69
Guest
Hi,
I'm trying to use a nested json file. I create the file with this:
I am using Newtonsoft.Json
[Serializable]
public class FormParams
{
//system.drawing.rectangle = 10; 10; 700; 500 ==> x, y, width, height
public int FrmX { get; set; }
public int FrmY { get; set; }
public int FrmHeight { get; set; }
public int FrmWidth { get; set; }
public int FrmWindowState { get; set; }
[NonSerialized]
public string SettingsFilePath;
}
public class FormSettings
{
public List<FormParams> FormMain { get; set; }
}
private void button1_Click(object sender, EventArgs e)
{
var FormPos = new FormSettings()
{
FormMain = new List<FormParams>()
{
new FormParams()
{
FrmX = this.Location.X,
FrmY = this.Location.Y,
FrmHeight = this.Height,
FrmWidth = this.Width,
FrmWindowState = 0
}
}
};
string json = JsonConvert.SerializeObject(FormPos, Formatting.Indented);
File.AppendAllText(@"c:\TEST.txt", json); //add file.exists
}
The resulting json text file is:
{
"FormMain": [
{
"FrmX": 50,
"FrmY": 50,
"FrmHeight": 488,
"FrmWidth": 816,
"FrmWindowState": 0
}
]
}
How can replace the value of "FrmHeight" without deleting the whole file and write it again.
Greatings,
Hans
Continue reading...
I'm trying to use a nested json file. I create the file with this:
I am using Newtonsoft.Json
[Serializable]
public class FormParams
{
//system.drawing.rectangle = 10; 10; 700; 500 ==> x, y, width, height
public int FrmX { get; set; }
public int FrmY { get; set; }
public int FrmHeight { get; set; }
public int FrmWidth { get; set; }
public int FrmWindowState { get; set; }
[NonSerialized]
public string SettingsFilePath;
}
public class FormSettings
{
public List<FormParams> FormMain { get; set; }
}
private void button1_Click(object sender, EventArgs e)
{
var FormPos = new FormSettings()
{
FormMain = new List<FormParams>()
{
new FormParams()
{
FrmX = this.Location.X,
FrmY = this.Location.Y,
FrmHeight = this.Height,
FrmWidth = this.Width,
FrmWindowState = 0
}
}
};
string json = JsonConvert.SerializeObject(FormPos, Formatting.Indented);
File.AppendAllText(@"c:\TEST.txt", json); //add file.exists
}
The resulting json text file is:
{
"FormMain": [
{
"FrmX": 50,
"FrmY": 50,
"FrmHeight": 488,
"FrmWidth": 816,
"FrmWindowState": 0
}
]
}
How can replace the value of "FrmHeight" without deleting the whole file and write it again.
Greatings,
Hans
Continue reading...