Class JsonSerialization | Serialization | 1.0.0-preview.5
docs.unity3d.com
    Show / Hide Table of Contents

    Class JsonSerialization

    High level API for serializing or deserializing json data from string, file or stream.

    Inheritance
    Object
    JsonSerialization
    Namespace: Unity.Serialization.Json
    Syntax
    public static class JsonSerialization

    Methods

    AddGlobalAdapter(IJsonAdapter)

    Adds the specified IJsonAdapter to the set of global adapters. This is be included by default in all JsonSerialization calls.

    Declaration
    public static void AddGlobalAdapter(IJsonAdapter adapter)
    Parameters
    Type Name Description
    IJsonAdapter adapter

    The adapter to add.

    Exceptions
    Type Condition
    ArgumentException

    The given adapter is already registered.

    AddGlobalMigration(IJsonMigration)

    Adds the specified IJsonMigration to the set of global adapters. This is be included by default in all JsonSerialization calls.

    Declaration
    public static void AddGlobalMigration(IJsonMigration migration)
    Parameters
    Type Name Description
    IJsonMigration migration

    The migration to add.

    Exceptions
    Type Condition
    ArgumentException

    The given migration is already registered.

    FromJson<T>(FileInfo, JsonSerializationParameters)

    Deserializes from the specified path and returns a new instance of T.

    Declaration
    public static T FromJson<T>(FileInfo file, JsonSerializationParameters parameters = default(JsonSerializationParameters))
    Parameters
    Type Name Description
    FileInfo file

    The file to read from.

    JsonSerializationParameters parameters

    The reader parameters to use.

    Returns
    Type Description
    T

    A new instance of T constructed from the serialized data.

    Type Parameters
    Name Description
    T

    The type to deserialize.

    FromJson<T>(Stream, JsonSerializationParameters)

    Deserializes from the specified stream and returns a new instance of T.

    Declaration
    public static T FromJson<T>(Stream stream, JsonSerializationParameters parameters = default(JsonSerializationParameters))
    Parameters
    Type Name Description
    Stream stream

    The stream to read from.

    JsonSerializationParameters parameters

    The reader parameters to use.

    Returns
    Type Description
    T

    A new instance of T constructed from the serialized data.

    Type Parameters
    Name Description
    T

    The type to deserialize.

    FromJson<T>(String, JsonSerializationParameters)

    Deserializes from the specified json string and returns a new instance of T.

    Declaration
    public static T FromJson<T>(string json, JsonSerializationParameters parameters = default(JsonSerializationParameters))
    Parameters
    Type Name Description
    String json

    The json string to read from.

    JsonSerializationParameters parameters

    The reader parameters to use.

    Returns
    Type Description
    T

    A new instance of T constructed from the serialized data.

    Type Parameters
    Name Description
    T

    The type to deserialize.

    FromJsonOverride<T>(FileInfo, ref T, JsonSerializationParameters)

    Deserializes from the specified path in to an existing instance of T.

    Declaration
    public static void FromJsonOverride<T>(FileInfo file, ref T container, JsonSerializationParameters parameters = default(JsonSerializationParameters))
    Parameters
    Type Name Description
    FileInfo file

    The file to read from.

    T container

    The reference to be overwritten.

    JsonSerializationParameters parameters

    The reader parameters to use.

    Type Parameters
    Name Description
    T

    The type to deserialize.

    FromJsonOverride<T>(Stream, ref T, JsonSerializationParameters)

    Deserializes from the specified stream in to an existing instance of T.

    Declaration
    public static void FromJsonOverride<T>(Stream stream, ref T container, JsonSerializationParameters parameters = default(JsonSerializationParameters))
    Parameters
    Type Name Description
    Stream stream

    The stream to read from.

    T container

    The reference to be overwritten.

    JsonSerializationParameters parameters

    The reader parameters to use.

    Type Parameters
    Name Description
    T

    The type to deserialize.

    FromJsonOverride<T>(String, ref T, JsonSerializationParameters)

    Deserializes from the specified json string in to an existing instance of T.

    Declaration
    public static void FromJsonOverride<T>(string json, ref T container, JsonSerializationParameters parameters = default(JsonSerializationParameters))
    Parameters
    Type Name Description
    String json

    The json string to read from.

    T container

    The reference to be overwritten.

    JsonSerializationParameters parameters

    The reader parameters to use.

    Type Parameters
    Name Description
    T

    The type to deserialize.

    RemoveGlobalAdapter(IJsonAdapter)

    Removes the specified IJsonAdapter from the set of global adapters.

    Declaration
    public static void RemoveGlobalAdapter(IJsonAdapter adapter)
    Parameters
    Type Name Description
    IJsonAdapter adapter

    The adapter to remove.

    Exceptions
    Type Condition
    ArgumentException

    The given adapter has not been registered.

    RemoveGlobalMigration(IJsonMigration)

    Removes the specified IJsonAdapter from the set of global adapters.

    Declaration
    public static void RemoveGlobalMigration(IJsonMigration migration)
    Parameters
    Type Name Description
    IJsonMigration migration

    The migration to remove.

    Exceptions
    Type Condition
    ArgumentException

    The given migration has not been registered.

    ToJson<T>(T, JsonSerializationParameters)

    Writes a property container to a json string.

    Declaration
    public static string ToJson<T>(T value, JsonSerializationParameters parameters = default(JsonSerializationParameters))
    Parameters
    Type Name Description
    T value

    The container to write.

    JsonSerializationParameters parameters

    The parameters to use when writing.

    Returns
    Type Description
    String

    A json string.

    Type Parameters
    Name Description
    T

    The type to serialize.

    ToJson<T>(FileInfo, T, JsonSerializationParameters)

    Serializes the given object to a json file at the specified path.

    Declaration
    public static void ToJson<T>(FileInfo file, T container, JsonSerializationParameters parameters = default(JsonSerializationParameters))
    Parameters
    Type Name Description
    FileInfo file

    The file to write to.

    T container

    The object to serialize.

    JsonSerializationParameters parameters

    The parameters to use when writing.

    Type Parameters
    Name Description
    T

    The type to serialize.

    ToJson<T>(JsonStringBuffer, T, JsonSerializationParameters)

    Writes a property container the specified buffer.

    Declaration
    public static void ToJson<T>(JsonStringBuffer buffer, T value, JsonSerializationParameters parameters = default(JsonSerializationParameters))
    Parameters
    Type Name Description
    JsonStringBuffer buffer

    The buffer to write the object to.

    T value

    The container to write.

    JsonSerializationParameters parameters

    The parameters to use when writing.

    Type Parameters
    Name Description
    T

    The type to serialize.

    TryFromJson<T>(FileInfo, out T, out DeserializationResult, JsonSerializationParameters)

    Deserializes from the specified path and returns a new instance of T.

    Declaration
    public static bool TryFromJson<T>(FileInfo file, out T container, out DeserializationResult result, JsonSerializationParameters parameters = default(JsonSerializationParameters))
    Parameters
    Type Name Description
    FileInfo file

    The file to read from.

    T container

    When this method returns, contains the deserialized value.

    DeserializationResult result

    The results structure containing any errors or exceptions.

    JsonSerializationParameters parameters

    The reader parameters to use.

    Returns
    Type Description
    Boolean

    True if the deserialization succeeded; otherwise, false.

    Type Parameters
    Name Description
    T

    The type to deserialize.

    TryFromJson<T>(Stream, out T, out DeserializationResult, JsonSerializationParameters)

    Deserializes from the specified stream and returns a new instance of T.

    Declaration
    public static bool TryFromJson<T>(Stream stream, out T container, out DeserializationResult result, JsonSerializationParameters parameters = default(JsonSerializationParameters))
    Parameters
    Type Name Description
    Stream stream

    The stream to read from.

    T container

    When this method returns, contains the deserialized value.

    DeserializationResult result

    The results structure containing any errors or exceptions.

    JsonSerializationParameters parameters

    The reader parameters to use.

    Returns
    Type Description
    Boolean

    True if the deserialization succeeded; otherwise, false.

    Type Parameters
    Name Description
    T

    The type to deserialize.

    TryFromJson<T>(String, out T, out DeserializationResult, JsonSerializationParameters)

    Deserializes from the specified json string and returns a new instance of T.

    Declaration
    public static bool TryFromJson<T>(string json, out T container, out DeserializationResult result, JsonSerializationParameters parameters = default(JsonSerializationParameters))
    Parameters
    Type Name Description
    String json

    The json string to read from.

    T container

    When this method returns, contains the deserialized value.

    DeserializationResult result

    The results structure containing any errors or exceptions.

    JsonSerializationParameters parameters

    The reader parameters to use.

    Returns
    Type Description
    Boolean

    True if the deserialization succeeded; otherwise, false.

    Type Parameters
    Name Description
    T

    The type to deserialize.

    TryFromJsonOverride<T>(FileInfo, ref T, out DeserializationResult, JsonSerializationParameters)

    Deserializes from the specified path in to an existing instance of T.

    Declaration
    public static bool TryFromJsonOverride<T>(FileInfo file, ref T container, out DeserializationResult result, JsonSerializationParameters parameters = default(JsonSerializationParameters))
    Parameters
    Type Name Description
    FileInfo file

    The file to read from.

    T container

    The reference to be overwritten.

    DeserializationResult result

    The results structure containing any errors or exceptions.

    JsonSerializationParameters parameters

    The reader parameters to use.

    Returns
    Type Description
    Boolean

    True if the deserialization succeeded; otherwise, false.

    Type Parameters
    Name Description
    T

    The type to deserialize.

    TryFromJsonOverride<T>(Stream, ref T, out DeserializationResult, JsonSerializationParameters)

    Deserializes from the specified stream in to an existing instance of T.

    Declaration
    public static bool TryFromJsonOverride<T>(Stream stream, ref T container, out DeserializationResult result, JsonSerializationParameters parameters = default(JsonSerializationParameters))
    Parameters
    Type Name Description
    Stream stream

    The stream to read from.

    T container

    The reference to be overwritten.

    DeserializationResult result

    The results structure containing any errors or exceptions.

    JsonSerializationParameters parameters

    The reader parameters to use.

    Returns
    Type Description
    Boolean

    True if the deserialization succeeded; otherwise, false.

    Type Parameters
    Name Description
    T

    The type to deserialize.

    TryFromJsonOverride<T>(String, ref T, out DeserializationResult, JsonSerializationParameters)

    Deserializes from the specified json string in to an existing instance of T.

    Declaration
    public static bool TryFromJsonOverride<T>(string json, ref T container, out DeserializationResult result, JsonSerializationParameters parameters = default(JsonSerializationParameters))
    Parameters
    Type Name Description
    String json

    The json string to read from.

    T container

    The reference to be overwritten.

    DeserializationResult result

    The results structure containing any errors or exceptions.

    JsonSerializationParameters parameters

    The reader parameters to use.

    Returns
    Type Description
    Boolean

    True if the deserialization succeeded; otherwise, false.

    Type Parameters
    Name Description
    T

    The type to deserialize.

    In This Article
    • Methods
      • AddGlobalAdapter(IJsonAdapter)
      • AddGlobalMigration(IJsonMigration)
      • FromJson<T>(FileInfo, JsonSerializationParameters)
      • FromJson<T>(Stream, JsonSerializationParameters)
      • FromJson<T>(String, JsonSerializationParameters)
      • FromJsonOverride<T>(FileInfo, ref T, JsonSerializationParameters)
      • FromJsonOverride<T>(Stream, ref T, JsonSerializationParameters)
      • FromJsonOverride<T>(String, ref T, JsonSerializationParameters)
      • RemoveGlobalAdapter(IJsonAdapter)
      • RemoveGlobalMigration(IJsonMigration)
      • ToJson<T>(T, JsonSerializationParameters)
      • ToJson<T>(FileInfo, T, JsonSerializationParameters)
      • ToJson<T>(JsonStringBuffer, T, JsonSerializationParameters)
      • TryFromJson<T>(FileInfo, out T, out DeserializationResult, JsonSerializationParameters)
      • TryFromJson<T>(Stream, out T, out DeserializationResult, JsonSerializationParameters)
      • TryFromJson<T>(String, out T, out DeserializationResult, JsonSerializationParameters)
      • TryFromJsonOverride<T>(FileInfo, ref T, out DeserializationResult, JsonSerializationParameters)
      • TryFromJsonOverride<T>(Stream, ref T, out DeserializationResult, JsonSerializationParameters)
      • TryFromJsonOverride<T>(String, ref T, out DeserializationResult, JsonSerializationParameters)
    Back to top
    Copyright © 2023 Unity Technologies — Terms of use
    • Legal
    • Privacy Policy
    • Cookies
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)
    "Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
    Generated by DocFX on 18 October 2023