Example #1
0
        /// <summary>
        /// Replaces the value of specified name.
        /// </summary>
        /// <param name="name">The name to replace the value of.</param>
        /// <param name="newvalue">The new value.</param>
        /// <returns></returns>
        public bool ReplaceValueOf(string name, string newvalue)
        {
            jr.updateOption(name, newvalue);
            string  jsonString = File.ReadAllText(pathnew);
            JObject jObject    = Newtonsoft.Json.JsonConvert.DeserializeObject(jsonString) as JObject;
            // Select a nested property using a single string:
            JToken jToken = jObject.SelectToken(name);

            jToken.Replace(newvalue);
            string updatedJsonString = jObject.ToString();

            Console.WriteLine("replacing value of " + name + " to " + newvalue);
            File.WriteAllText(pathnew, updatedJsonString);
            return(true);
        }