Find and replace a string in a JSON file in C#
Hi,I have a JSON file. find a string like "dark_theme" and in the object find "primaryColor" after find "primaryColor" key I want to change values
{
"dark_theme": {
"primaryColor": "#FF7C4C"
}
}
I found this code. but it is not to update my JSON file. It displays string has been changed when
I am doing debug.
string jsonString = File.ReadAllText(HttpContext.Current.Server.MapPath("~/Companydata/2061/DarkJSON.json"));
JObject data = JObject.Parse(jsonString);
JObject hero = (JObject)data["dark_theme"];
hero["primaryColor"] = "#E9967A"; // "god-like strength" hax; modifies the JObject
jsonString = data.ToString(); // re-serialize tree, along with modifications