Struct JsonWriter
The JsonWriter provides forward only writing of encoded JSON text.
Inherited Members
Namespace: Unity.Serialization.Json
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(Int32, Allocator, JsonWriterOptions)
Initializes a new instance of JsonWriter.
Declaration
public JsonWriter(int initialCapacity, Allocator label, JsonWriterOptions options = default(JsonWriterOptions))
Parameters
Type | Name | Description |
---|---|---|
Int32 | 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(JsonWriterOptions))
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()
Implements
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, Boolean)
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. |
Boolean | 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, Int32)
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. |
Int32 | value | The value to write. |
WriteKeyValue(String, Int64)
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. |
Int64 | value | The value to write. |
WriteKeyValue(String, Single)
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. |
Single | 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, UInt32)
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. |
UInt32 | value | The value to write. |
WriteKeyValue(String, UInt64)
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. |
UInt64 | 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(Boolean)
Writes the specified boolean value to the buffer with the correct formatting.
Declaration
public void WriteValue(bool value)
Parameters
Type | Name | Description |
---|---|---|
Boolean | 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(Int32)
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 |
---|---|---|
Int32 | value | The value to write. |
WriteValue(Int64)
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 |
---|---|---|
Int64 | value | The value to write. |
WriteValue(Single)
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 |
---|---|---|
Single | 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(UInt32)
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 |
---|---|---|
UInt32 | value | The value to write. |
WriteValue(UInt64)
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 |
---|---|---|
UInt64 | 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. |