docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Struct JsonWriter.Unsafe

    This object can be used to build a JSON string in an unsafe or bursted context.

    Implements
    IDisposable
    Inherited Members
    ValueType.Equals(object)
    ValueType.GetHashCode()
    object.Equals(object, object)
    object.GetType()
    object.ReferenceEquals(object, object)
    Namespace: Unity.Serialization.Json
    Assembly: Unity.Serialization.dll
    Syntax
    public struct JsonWriter.Unsafe : IDisposable

    Constructors

    Unsafe(int, Allocator, JsonWriterOptions)

    Initializes a new instance of JsonWriter.Unsafe.

    Declaration
    public Unsafe(int initialCapacity, Allocator label, JsonWriterOptions options = default)
    Parameters
    Type Name Description
    int initialCapacity

    The initial capacity to use for the internal buffer.

    Allocator label

    The allocator label to use.

    JsonWriterOptions options

    Options to define custom behaviour.

    Properties

    Length

    The current number of characters in the buffer.

    Declaration
    public int Length { get; }
    Property Value
    Type Description
    int

    The character count.

    Methods

    Clear()

    Clears the writer for re-use.

    Declaration
    public void Clear()

    Dispose()

    Declaration
    public void Dispose()

    GetUnsafeReadOnlyPtr()

    Gets a pointer to the memory buffer containing the characters.

    Declaration
    public char* GetUnsafeReadOnlyPtr()
    Returns
    Type Description
    char*

    A pointer to the memory buffer.

    ToString()

    Declaration
    public override string ToString()
    Returns
    Type Description
    string
    Overrides
    ValueType.ToString()

    WriteBeginArray()

    Writes the begin array token '[' and starts an array scope.

    Declaration
    public void WriteBeginArray()

    WriteBeginArray(char*, int)

    Writes a keyed begin array token '"key": [' and starts an array scope.

    Declaration
    public void WriteBeginArray(char* ptr, int length)
    Parameters
    Type Name Description
    char* ptr

    The pointer to the key.

    int length

    The length of the key.

    WriteBeginObject()

    Writes the begin object token '{' and starts an object scope.

    Declaration
    public void WriteBeginObject()

    WriteBeginObject(char*, int)

    Writes a keyed begin object token '"key": {' and starts an object scope.

    Declaration
    public void WriteBeginObject(char* ptr, int length)
    Parameters
    Type Name Description
    char* ptr

    The pointer to the key.

    int length

    The length of the key.

    WriteEndArray()

    Writes the end array token ']' and closes the array scope.

    Declaration
    public void WriteEndArray()

    WriteEndObject()

    Writes the end object token '}' and closes an object scope.

    Declaration
    public void WriteEndObject()

    WriteKey(char*, int)

    Writes the specified key to the buffer with the correct formatting.

    Declaration
    public void WriteKey(char* ptr, int length)
    Parameters
    Type Name Description
    char* ptr

    The pointer to the key.

    int length

    The length of the key.

    WriteKeyValue(char*, int, char*, int)

    Writes the specified key-value pair with to the buffer with the correct formatting.

    Declaration
    public void WriteKeyValue(char* keyPtr, int keyLength, char* valuePtr, int valueLength)
    Parameters
    Type Name Description
    char* keyPtr

    The pointer to the key.

    int keyLength

    The length of the key.

    char* valuePtr

    The pointer to the value.

    int valueLength

    The length of the value.

    WriteKeyValue(char*, int, int)

    Writes the specified key-value pair with to the buffer with the correct formatting.

    Declaration
    public void WriteKeyValue(char* ptr, int length, int value)
    Parameters
    Type Name Description
    char* ptr

    The pointer to the key.

    int length

    The length of the key.

    int value

    The value to write.

    WriteKeyValue(char*, int, long)

    Writes the specified key-value pair with to the buffer with the correct formatting.

    Declaration
    public void WriteKeyValue(char* ptr, int length, long value)
    Parameters
    Type Name Description
    char* ptr

    The pointer to the key.

    int length

    The length of the key.

    long value

    The value to write.

    WriteKeyValue(char*, int, float)

    Writes the specified key-value pair with to the buffer with the correct formatting.

    Declaration
    public void WriteKeyValue(char* ptr, int length, float value)
    Parameters
    Type Name Description
    char* ptr

    The pointer to the key.

    int length

    The length of the key.

    float value

    The value to write.

    WriteKeyValue(char*, int, uint)

    Writes the specified key-value pair with to the buffer with the correct formatting.

    Declaration
    public void WriteKeyValue(char* ptr, int length, uint value)
    Parameters
    Type Name Description
    char* ptr

    The pointer to the key.

    int length

    The length of the key.

    uint value

    The value to write.

    WriteKeyValue(char*, int, ulong)

    Writes the specified key-value pair with to the buffer with the correct formatting.

    Declaration
    public void WriteKeyValue(char* ptr, int length, ulong value)
    Parameters
    Type Name Description
    char* ptr

    The pointer to the key.

    int length

    The length of the key.

    ulong value

    The value to write.

    WriteKeyValueLiteral(char*, int, char*, int)

    Writes the specified key-value pair with to the buffer with the correct formatting.

    Declaration
    public void WriteKeyValueLiteral(char* keyPtr, int keyLength, char* valuePtr, int valueLength)
    Parameters
    Type Name Description
    char* keyPtr

    The pointer to the key.

    int keyLength

    The length of the key.

    char* valuePtr

    The pointer to the value.

    int valueLength

    The length of the value.

    WriteNull()

    Writes the literal value 'null' to the buffer with the correct formatting.

    Declaration
    public void WriteNull()

    WriteValue(bool)

    Writes the specified boolean value to the buffer with the correct formatting.

    Declaration
    public void WriteValue(bool value)
    Parameters
    Type Name Description
    bool value

    The value to write.

    WriteValue(char)

    Writes the specified char value to the buffer with the correct formatting.

    Declaration
    public void WriteValue(char value)
    Parameters
    Type Name Description
    char value

    The value to write.

    WriteValue(char*, int)

    Writes the specified string value to the buffer as an encoded JSON string.

    Declaration
    public void WriteValue(char* ptr, int length)
    Parameters
    Type Name Description
    char* ptr

    The pointer to the string value.

    int length

    The length of the string value.

    WriteValue(int)

    Writes the specified 32-bit signed integer value to the buffer with the correct formatting.

    Declaration
    public void WriteValue(int value)
    Parameters
    Type Name Description
    int value

    The value to write.

    WriteValue(long)

    Writes the specified 64-bit signed integer value to the buffer with the correct formatting.

    Declaration
    public void WriteValue(long value)
    Parameters
    Type Name Description
    long value

    The value to write.

    WriteValue(float)

    Writes the specified 32-bit floating-point value to the buffer with the correct formatting.

    Declaration
    public void WriteValue(float value)
    Parameters
    Type Name Description
    float value

    The value to write.

    WriteValueLiteral(char)

    Writes the specified char to the buffer as a literal.

    Declaration
    public void WriteValueLiteral(char value)
    Parameters
    Type Name Description
    char value

    The value to write.

    Remarks

    If you need to write out a string value with quotes WriteValue(char).

    WriteValueLiteral(char*, int)

    Writes the specified string to the buffer as a literal.

    Declaration
    public void WriteValueLiteral(char* ptr, int length)
    Parameters
    Type Name Description
    char* ptr

    The pointer to the string value.

    int length

    The length of the string value.

    Remarks

    If you need to write out a string value with quotes WriteValue(char*, int).

    Exceptions
    Type Condition
    InvalidOperationException

    Validation is enabled, and the operation would result in writing invalid JSON.

    Implements

    IDisposable
    In This Article
    Back to top
    Copyright © 2025 Unity Technologies — Trademarks and terms of use
    • Legal
    • Privacy Policy
    • Cookie Policy
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)