string json = "{ 'name': 'John', 'age': 30, 'city': 'New York' }"; JObject obj = JObject.Parse(json); string name = (string)obj["name"]; int age = (int)obj["age"]; string city = (string)obj["city"]; Console.WriteLine($"Name: {name}"); Console.WriteLine($"Age: {age}"); Console.WriteLine($"City: {city}");
JObject obj = new JObject(); obj.Add("name", "John"); obj.Add("age", 30); obj.Add("city", "New York"); string json = obj.ToString(); Console.WriteLine(json);This example shows how we can create a new JSON object using the JObject class and add properties to it. We then convert the object to a JSON string and print it to the console. Overall, JObject allows us to easily manipulate JSON objects in C# and is a useful tool for applications that deal with JSON data.