I have List of companies and im trying to add a new company to a json file but It either doesn't go into the right place or it overwrites everything in that section. Im using Json .net to do this
I have this and Im trying to add a company to it
"Companies": []
Ive tried doing this but it just overwrites what is already in the "Companies" area.
Company company = new Company
{
CompanyName = textBox1.Text,
IPO = Convert.ToDouble(textBox2.Text),
Category = CategorycomboBox1.SelectedItem.ToString(),
Description = textBox4.Text,
StartDate = Convert.ToInt32(textBox5.Text)
};
AddProductListItemsToFinishedJSON(company);
AddNewsArticlesListItemsToFinishedJSON(company);
JObject jo = JObject.FromObject(company);
string NewCompanyJson = jo.ToString();
string FileWritingToJson = File.ReadAllText(path);
var NewCompanyJsonParsed = JObject.Parse(NewCompanyJson);
var FileWritingToJsonParsed = JObject.Parse(FileWritingToJson);
Debug.WriteLine(FileWritingToJson);
Debug.WriteLine(NewCompanyJson);
FileWritingToJsonParsed["Companies"] = NewCompanyJsonParsed;
Debug.WriteLine("-----------------------");
Debug.WriteLine(FileWritingToJsonParsed);
File.WriteAllText(@"D:\COMPTESTTES.json", FileWritingToJsonParsed.ToString());
SaveJSONFile(company);
It either overwrites that section or adds it to the bottom of the file.