Struct JsonWriter
The JsonWriter provides forward only writing of encoded JSON text.
Implements
Inherited Members
Namespace: Unity.Serialization.Json
Assembly: Unity.Serialization.dll
Syntax
public struct JsonWriter : IDisposable
Remarks
A method that attempts to write invalid JSON throws an InvalidOperationException with a context-specific error message.
Constructors
JsonWriter(int, Allocator, JsonWriterOptions)
Initializes a new instance of JsonWriter.
Declaration
public JsonWriter(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. |
JsonWriter(Allocator, JsonWriterOptions)
Initializes a new instance of JsonWriter.
Declaration
public JsonWriter(Allocator label, JsonWriterOptions options = default)
Parameters
| Type | Name | Description |
|---|---|---|
| Allocator | label | The allocator label to use. |
| JsonWriterOptions | options | Options to define custom behaviour. |
Methods
AsUnsafe()
Returns the unsafe writer which can be used in bursted jobs.
Declaration
public JsonWriter.Unsafe AsUnsafe()
Returns
| Type | Description |
|---|---|
| JsonWriter.Unsafe | The unsafe writer. |
Clear()
Clears the writer for re-use.
Declaration
public void Clear()
Dispose()
Declaration
public void Dispose()
ToString()
Declaration
public override string ToString()
Returns
| Type | Description |
|---|---|
| string |
Overrides
WriteArrayScope(string)
Creates a collection scope which writes the beginning '"key": [' and ending ']' tokens.
Declaration
public JsonWriter.ArrayScope WriteArrayScope(string key = null)
Parameters
| Type | Name | Description |
|---|---|---|
| string | key | The key to write. |
Returns
| Type | Description |
|---|---|
| JsonWriter.ArrayScope | A disposable collection scope. |
WriteBeginArray(string)
Writes a keyed array token '"key": [' and opens an array scope.
Declaration
public void WriteBeginArray(string key = null)
Parameters
| Type | Name | Description |
|---|---|---|
| string | key | The key to write. |
WriteBeginObject(string)
Writes a keyed object token '"key": [' and opens an object scope.
Declaration
public void WriteBeginObject(string key = null)
Parameters
| Type | Name | Description |
|---|---|---|
| string | key | The key to write. |
WriteEndArray()
Writes the end array token ']' and closes the array scope.
Declaration
public void WriteEndArray()
WriteEndObject()
Writes the end object token '}' and closes the object scope.
Declaration
public void WriteEndObject()
WriteKey(string)
Writes the specified key to the buffer with the correct formatting.
Declaration
public void WriteKey(string key)
Parameters
| Type | Name | Description |
|---|---|---|
| string | key | The key to write. |
WriteKeyValue(string, bool)
Writes the specified key-value pair with to the buffer with the correct formatting.
Declaration
public void WriteKeyValue(string key, bool value)
Parameters
| Type | Name | Description |
|---|---|---|
| string | key | The key to write. |
| bool | value | The value to write. |
WriteKeyValue(string, double)
Writes the specified key-value pair with to the buffer with the correct formatting.
Declaration
public void WriteKeyValue(string key, double value)
Parameters
| Type | Name | Description |
|---|---|---|
| string | key | The key to write. |
| double | value | The value to write. |
WriteKeyValue(string, int)
Writes the specified key-value pair with to the buffer with the correct formatting.
Declaration
public void WriteKeyValue(string key, int value)
Parameters
| Type | Name | Description |
|---|---|---|
| string | key | The key to write. |
| int | value | The value to write. |
WriteKeyValue(string, long)
Writes the specified key-value pair with to the buffer with the correct formatting.
Declaration
public void WriteKeyValue(string key, long value)
Parameters
| Type | Name | Description |
|---|---|---|
| string | key | The key to write. |
| long | value | The value to write. |
WriteKeyValue(string, float)
Writes the specified key-value pair with to the buffer with the correct formatting.
Declaration
public void WriteKeyValue(string key, float value)
Parameters
| Type | Name | Description |
|---|---|---|
| string | key | The key to write. |
| float | value | The value to write. |
WriteKeyValue(string, string)
Writes the specified key-value pair with to the buffer with the correct formatting.
Declaration
public void WriteKeyValue(string key, string value)
Parameters
| Type | Name | Description |
|---|---|---|
| string | key | The key to write. |
| string | value | The value to write. |
WriteKeyValue(string, uint)
Writes the specified key-value pair with to the buffer with the correct formatting.
Declaration
public void WriteKeyValue(string key, uint value)
Parameters
| Type | Name | Description |
|---|---|---|
| string | key | The key to write. |
| uint | value | The value to write. |
WriteKeyValue(string, ulong)
Writes the specified key-value pair with to the buffer with the correct formatting.
Declaration
public void WriteKeyValue(string key, ulong value)
Parameters
| Type | Name | Description |
|---|---|---|
| string | key | The key to write. |
| ulong | value | The value to write. |
WriteKeyValueLiteral(string, string)
Writes the specified key-value pair with to the buffer with the correct formatting.
Declaration
public void WriteKeyValueLiteral(string key, string value)
Parameters
| Type | Name | Description |
|---|---|---|
| string | key | The key to write. |
| string | value | The value to write. |
WriteNull()
Writes the literal value 'null' to the buffer with the correct formatting.
Declaration
public void WriteNull()
WriteObjectScope(string)
Creates an object scope which writes the beginning '"key": {' and ending '}' tokens.
Declaration
public JsonWriter.ObjectScope WriteObjectScope(string key = null)
Parameters
| Type | Name | Description |
|---|---|---|
| string | key | The key to write. |
Returns
| Type | Description |
|---|---|
| JsonWriter.ObjectScope | A disposable object scope. |
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(double)
Writes the specified 64-bit floating-point value to the buffer with the correct formatting.
Declaration
public void WriteValue(double value)
Parameters
| Type | Name | Description |
|---|---|---|
| double | value | The value to write. |
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. |
WriteValue(string)
Writes the specified string value to the buffer with the correct formatting.
Declaration
public void WriteValue(string value)
Parameters
| Type | Name | Description |
|---|---|---|
| string | value | The value to write. |
WriteValue(uint)
Writes the specified 32-bit unsigned integer value to the buffer with the correct formatting.
Declaration
public void WriteValue(uint value)
Parameters
| Type | Name | Description |
|---|---|---|
| uint | value | The value to write. |
WriteValue(ulong)
Writes the specified 64-bit unsigned integer value to the buffer with the correct formatting.
Declaration
public void WriteValue(ulong value)
Parameters
| Type | Name | Description |
|---|---|---|
| ulong | value | The value to write. |
WriteValueLiteral(char)
Writes the specified char value to the buffer with the correct formatting.
Declaration
public void WriteValueLiteral(char value)
Parameters
| Type | Name | Description |
|---|---|---|
| char | value | The value to write. |
WriteValueLiteral(string)
Writes the specified string value to the buffer with the correct formatting.
Declaration
public void WriteValueLiteral(string value)
Parameters
| Type | Name | Description |
|---|---|---|
| string | value | The value to write. |