Table of Contents

Class JsonConversion

Namespace
PAC.Json
public static class JsonConversion
Inheritance
JsonConversion
Inherited Members

Methods

FromJson<T>(JsonData, JsonConverterSet, bool)

Attempts to convert the JSON data into a C# object of the given type.

public static T FromJson<T>(JsonData jsonData, JsonConversion.JsonConverterSet customConverters, bool allowUndefinedConversions = false)

Parameters

jsonData JsonData

The JSON data to convert.

customConverters JsonConversion.JsonConverterSet

A collection of JsonConverter objects that defined custom conversions for certain data types.

allowUndefinedConversions bool

If false, an exception will be thrown if the code encounters a type that can not be converted using conversions for primitive JSON types and/or custom converters.

Returns

T

Type Parameters

T

The type to convert the JSON into.

FromJson<T>(JsonData, JsonConverterSet, bool, HashSet<JsonData>)

Attempts to convert the JSON data into a C# object of the given type.

public static T FromJson<T>(JsonData jsonData, JsonConversion.JsonConverterSet customConverters, bool allowUndefinedConversions, HashSet<JsonData> dataAlreadyTryingToConvert)

Parameters

jsonData JsonData

The JSON data to convert.

customConverters JsonConversion.JsonConverterSet

A collection of JsonConverter objects that defined custom conversions for certain data types.

allowUndefinedConversions bool

If false, an exception will be thrown if the code encounters a type that can not be converted using conversions for primitive JSON types and/or custom converters.

dataAlreadyTryingToConvert HashSet<JsonData>

The JSON data objects trying to be converted in the current function call stack. Used to prevent infinite loops when converting objects with circular references.

Returns

T

Type Parameters

T

The type to convert the JSON into.

FromJson<T>(JsonData, bool)

Attempts to convert the JSON data into a C# object of the given type.

public static T FromJson<T>(JsonData jsonData, bool allowUndefinedConversions = false)

Parameters

jsonData JsonData

The JSON data to convert.

allowUndefinedConversions bool

If false, an exception will be thrown if the code encounters a type that can not be converted using conversions for primitive JSON types and/or custom converters.

Returns

T

Type Parameters

T

The type to convert the JSON into.

ToJson(object, JsonConverterSet, bool)

Attempts to convert the C# object into JSON data.

NOTE: When converting an enum value which has more than one name, one of those names will be chosen, but not necessarily the one originally used to assign that value. E.g. for an enum with values Value1 = 0, Value2 = 0, Value3 = 1, converting Value1 into JSON may end up as "Value2".

public static JsonData ToJson(object obj, JsonConversion.JsonConverterSet customConverters, bool allowUndefinedConversions = false)

Parameters

obj object

The object to convert into JSON.

customConverters JsonConversion.JsonConverterSet

A collection of JsonConverter objects that defined custom conversions for certain data types.

allowUndefinedConversions bool

If false, an exception will be thrown if the code encounters a type that can not be converted using conversions for primitive JSON types and/or custom converters.

Returns

JsonData

ToJson(object, bool)

Attempts to convert the C# object into JSON data.

NOTE: When converting an enum value which has more than one name, one of those names will be chosen, but not necessarily the one originally used to assign that value. E.g. for an enum with values Value1 = 0, Value2 = 0, Value3 = 1, converting Value1 into JSON may end up as "Value2".

public static JsonData ToJson(object obj, bool allowUndefinedConversions = false)

Parameters

obj object

The object to convert into JSON.

allowUndefinedConversions bool

If false, an exception will be thrown if the code encounters a type that can not be converted using conversions for primitive JSON types and/or custom converters.

Returns

JsonData