using Newtonsoft.Json; using System.IO; var writer = new JsonTextWriter(new StringWriter()); writer.WriteStartArray(); writer.WriteValue("First element"); writer.WriteValue("Second element"); writer.WriteEndArray(); writer.Close();
using Newtonsoft.Json; using System.IO; var writer = new JsonTextWriter(new StringWriter()); writer.WriteStartObject(); writer.WritePropertyName("name"); writer.WriteValue("John"); writer.WritePropertyName("age"); writer.WriteValue(30); writer.WriteEndObject(); writer.Close();In this example, we create a new JsonTextWriter instance and write a JSON object with two properties - name and age. Finally, we close the writer to ensure that all the data is correctly formatted. The package library for the JsonWriter Close method is Newtonsoft.Json.