private static void WriterSystemJsonBasic(bool formatted, bool skipValidation, ArrayFormatterWrapper output, ReadOnlySpan <int> data) { var state = new JsonWriterState(options: new JsonWriterOptions { Indented = formatted, SkipValidation = skipValidation }); var json = new Utf8JsonWriter2(output, state); json.WriteStartObject(); json.WriteNumber("age", 42); json.WriteString("first", "John"); json.WriteString("last", "Smith"); json.WriteStartArray("phoneNumbers"); json.WriteStringValue("425-000-1212"); json.WriteStringValue("425-000-1213"); json.WriteEndArray(); json.WriteStartObject("address"); json.WriteString("street", "1 Microsoft Way"); json.WriteString("city", "Redmond"); json.WriteNumber("zip", 98052); json.WriteEndObject(); json.WriteStartArray("ExtraArray"); for (var i = 0; i < data.Length; i++) { json.WriteNumberValue(data[i]); } json.WriteEndArray(); json.WriteEndObject(); json.Flush(); }
//[Benchmark] public void WriteNumberUnescapedUtf16() { _arrayFormatterWrapper.Clear(); var state = new JsonWriterState(options: new JsonWriterOptions { Indented = Formatted, SkipValidation = SkipValidation }); var json = new Utf8JsonWriter2(_arrayFormatterWrapper, state); json.WriteStartObject(); for (int i = 0; i < 100; i++) { json.WriteNumber("first", value: 123456, suppressEscaping: true); } json.WriteEndObject(); json.Flush(); }