I'm having troubles making JSON file from my Server class. This is my class:
public class CsServerInfo
{
public string ip { get; set; }
public string name { get; set; }
}
The idea is to add new servers into JSON file on a Button Click. It means every time I click on a button (in a WPF window which has TextBoxes for IP and Name properties) a new server should be added into JSON file.
CsServerInfo newServ = new CsServerInfo();
newServ.ip = this.serverIP.Text;
newServ.name = this.serverName.Text;
string json = JsonConvert.SerializeObject(newServ);
System.IO.File.AppendAllText(@"C:\JSON4.json", json);
The problem is I get JSON file that is not correctly formatted:
{"ip":"52.45.24.2","name":"new"}{"ip":"45.45.45.4","name":"new2"}
There's no comma between the servers and if I use ToArray()I get:
[{"ip":"52.45.24.2","name":"new"}][{"ip":"45.45.45.4","name":"new2"}]
Correct format should be [{server properties}, {another server}] but I'm not able to get that. Thanks for your help