This C# program demonstrates how to create, access, and modify a JSON document with the Newtonsoft Json package. Newtonsoft.json is a Nuget package that must be installed in order to run this program.
using System; // Requires Nuget Newtonsoft.Json package using Newtonsoft.Json.Linq; namespace JsonSimpleUsage { internal class Program { static void Main(string[] args) { string sJsonString = @"{ ""Passages"": [ {""Revelation3_15_16"": ""I know your works: you are neither cold nor hot. Would that you were cold or hot! So, because you are lukewarm, and neither cold nor hot, I will spew you out of my mouth.""}, {""Matthew5_20"": ""For I tell you, unless your righteousness exceeds that of the scribes and Pharisees, you will never enter the kingdom of heaven.""}, ], ""Version"": ""Revised Standard Version Catholic Edition (RSVCE)"" }"; JObject qJObject = JObject.Parse(sJsonString); // Add an element for the publication year qJObject["Year"] = "AD 2006"; Console.WriteLine(qJObject.ToString()); Console.WriteLine("\n\nSelect the version = " + qJObject.SelectToken("..Version").ToString()); Console.WriteLine("\n\nSelect passage[1] = " + qJObject.SelectToken("..Passages[1]").ToString()); } } }
{ "Passages": [ { "Revelation3_15_16": "I know your works: you are neither cold nor hot. Would that you were cold or hot! So, because you are lukewarm, and neither cold nor hot, I will spew you out of my mouth." }, { "Matthew5_20": "For I tell you, unless your righteousness exceeds that of the scribes and Pharisees, you will never enter the kingdom of heaven." }, { "Matthew7_15_20": "Beware of false prophets, who come to you in sheep's clothing but inwardly are ravenous wolves. You will know them by their fruits. Are grapes gathered from thorns, or figs from thistles? So, every sound tree bears good fruit, but the bad tree bears evil fruit. A sound tree cannot bear evil fruit, nor can a bad tree bear good fruit. Every tree that does not bear good fruit is cut down and thrown into the fire. Thus you will know them by their fruits." } ], "Version": "Revised Standard Version Catholic Edition (RSVCE)", "Year": "AD 2006" } Select the version = Revised Standard Version Catholic Edition (RSVCE) Select passage[1] = { "Matthew5_20": "For I tell you, unless your righteousness exceeds that of the scribes and Pharisees, you will never enter the kingdom of heaven." } Press any key to continue . . .
© 20072025 XoaX.net LLC. All rights reserved.