JsonWriter.WriteObjectEnd C# (CSharp) Method

WriteObjectEnd() public method

public WriteObjectEnd ( ) : void
return void
        public void WriteObjectEnd ()
        {
            DoValidation (Condition.InObject);
            PutNewline (false);

            ctx_stack.Pop ();
            if (ctx_stack.Count == 1)
                has_reached_end = true;
            else {
                context = ctx_stack.Peek ();
                context.ExpectingValue = false;
            }

            Unindent ();
            Put ("}");
        }

Usage Example

Example #1
0
    void WriteResponseForPostJson(HttpRequest request, HttpResponse response)
    {
        // read request JSON
        uint requestedCount = ReadCount(request.Body);

        // write response JSON
        var json = new JsonWriter<ResponseFormatter>(response.Body, prettyPrint: false);
        json.WriteObjectStart();
        json.WriteArrayStart();
        for (int i = 0; i < requestedCount; i++) {
            json.WriteString("hello!"); 
        }
        json.WriteArrayEnd();
        json.WriteObjectEnd();

        // write headers
        var headers = response.Headers;
        headers.AppendHttpStatusLine(HttpVersion.V1_1, 200, new Utf8String("OK"));
        headers.Append("Content-Length : ");
        headers.Append(response.Body.CommitedBytes);
        headers.AppendHttpNewLine();
        headers.Append("Content-Type : text/plain; charset=UTF-8");
        headers.AppendHttpNewLine();
        headers.Append("Server : .NET Core Sample Server");
        headers.AppendHttpNewLine();
        headers.Append("Date : ");
        headers.Append(DateTime.UtcNow, 'R');
        headers.AppendHttpNewLine();
        headers.AppendHttpNewLine();
    }
All Usage Examples Of JsonWriter::WriteObjectEnd