public WriteRaw ( string json ) : void | ||
json | string | The raw JSON to write. |
return | void |
using Newtonsoft.Json; string json = "{ \"name\" : \"John\", \"age\" : 30 }"; using StreamWriter sw = new StreamWriter("output.json"); using JsonTextWriter writer = new JsonTextWriter(sw); writer.WriteStartObject(); writer.WriteRaw(json); writer.WriteEndObject();
using Newtonsoft.Json; using System.IO; using System.Net; HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://example.com/api/users"); HttpWebResponse response = (HttpWebResponse)request.GetResponse(); using StreamReader sr = new StreamReader(response.GetResponseStream()); string json = sr.ReadToEnd(); using StreamWriter sw = new StreamWriter("output.json"); using JsonTextWriter writer = new JsonTextWriter(sw); writer.WriteStartObject(); writer.WritePropertyName("users"); writer.WriteRaw(json); writer.WriteEndObject();In this example, a web request is made to an API endpoint and the JSON response is read into a string. The JSON string is then written to an output file using a JsonTextWriter. The WritePropertyName method is used to set the name of the property that the JSON will be written to in the output file. Package Library: Newtonsoft.Json can be downloaded and added as a NuGet package to a C# project using Visual Studio. The package library is "Newtonsoft.Json".
public WriteRaw ( string json ) : void | ||
json | string | The raw JSON to write. |
return | void |