Skip to content

Latest commit

 

History

History
31 lines (27 loc) · 890 Bytes

CreateJsonJTokenWriter.md

File metadata and controls

31 lines (27 loc) · 890 Bytes

Create JSON with JTokenWriter

This sample creates Argon.JObject and Argon.JArray instances using a Argon.JTokenWriter.

var writer = new JTokenWriter();
writer.WriteStartObject();
writer.WritePropertyName("name1");
writer.WriteValue("value1");
writer.WritePropertyName("name2");
writer.WriteStartArray();
writer.WriteValue(1);
writer.WriteValue(2);
writer.WriteEndArray();
writer.WriteEndObject();

var o = (JObject) writer.Token;

Console.WriteLine(o.ToString());
// {
//   "name1": "value1",
//   "name2": [
//     1,
//     2
//   ]
// }

snippet source | anchor