Class JsonUtil
- Namespace
- Vintagestory.API.Common
- Assembly
- VintagestoryAPI.dll
public static class JsonUtil
- Inheritance
-
JsonUtil
- Inherited Members
Properties
DefaultLoadSettings
public static JsonLoadSettings DefaultLoadSettings { get; }
Property Value
- JsonLoadSettings
DefaultTextJsonSerializerOptions
public static JsonSerializerOptions DefaultTextJsonSerializerOptions { get; }
Property Value
Methods
CreateSerializerForDomain(string, JsonSerializerSettings?)
public static JsonSerializer CreateSerializerForDomain(string domain, JsonSerializerSettings? settings = null)
Parameters
domainstringsettingsJsonSerializerSettings
Returns
- JsonSerializer
DeserializeFastFromFile<T>(string, JsonSerializerOptions?)
Deserializes a file using System.Text.Json. Which means you need to make sure your objects do have the proper fields marked with System.Text.Json annotations to include and exclude them. The defaults for what to include and exclude are different from Newtonsoft.Json.
public static T? DeserializeFastFromFile<T>(string path, JsonSerializerOptions? settings = null)
Parameters
pathstringFilepath
settingsJsonSerializerOptionsIf this is not specified, we set IncludeFields=true, WriteIndented=true and use Encoder=JavaScriptEncoder.Create(UnicodeRanges.All)
Returns
- T
Type Parameters
T
DeserializeFast<T>(string, JsonSerializerOptions?)
Deserializes a string using System.Text.Json. Which means you need to make sure your objects do have the proper fields marked with System.Text.Json annotation to include and exclude them. The defaults for what to include and exclude are different from Newtonsoft.Json.
public static T? DeserializeFast<T>(string json, JsonSerializerOptions? settings = null)
Parameters
jsonstringsettingsJsonSerializerOptionsIf this is not specified, we set IncludeFields=true, WriteIndented=true and use Encoder=JavaScriptEncoder.Create(UnicodeRanges.All)
Returns
- T
Type Parameters
T
FromBytes<T>(byte[])
Reads a Json object, and converts it to the designated type.
public static T? FromBytes<T>(byte[] data)
Parameters
databyte[]The json object.
Returns
- T
Type Parameters
TThe designated type
FromString<T>(string)
public static T? FromString<T>(string data)
Parameters
datastring
Returns
- T
Type Parameters
T
PopulateObject(object, JToken, JsonSerializer)
public static void PopulateObject(object toPopulate, JToken token, JsonSerializer js)
Parameters
toPopulateobjecttokenJTokenjsJsonSerializer
PopulateObject(object, string, string, JsonSerializerSettings?)
public static void PopulateObject(object toPopulate, string text, string domain, JsonSerializerSettings? settings = null)
Parameters
Populate<T>(JToken, T)
public static void Populate<T>(this JToken value, T target) where T : class
Parameters
valueJTokentargetT
Type Parameters
T
SerializeFastToFile<T>(string, T, JsonSerializerOptions?)
Serializes an object to a file using System.Text.Json. Which means you need to make sure your objects do have the proper fields marked with System.Text.Json annotations to include and exclude them. The defaults for what to include and exclude are different from Newtonsoft.Json.
public static void SerializeFastToFile<T>(string path, T data, JsonSerializerOptions? settings = null)
Parameters
pathstringFilepath
dataTsettingsJsonSerializerOptionsIf this is not specified, we set IncludeFields=true, WriteIndented=true and use Encoder=JavaScriptEncoder.Create(UnicodeRanges.All)
Type Parameters
T
SerializeFast<T>(T, JsonSerializerOptions?)
Serializes an object to a string using System.Text.Json. Which means you need to make sure your objects do have the proper fields marked with System.Text.Json annotation to include and exclude them. The defaults for what to include and exclude are different from Newtonsoft.Json.
public static string SerializeFast<T>(T data, JsonSerializerOptions? settings = null)
Parameters
dataTsettingsJsonSerializerOptionsIf this is not specified, we set IncludeFields=true, WriteIndented=true and use Encoder=JavaScriptEncoder.Create(UnicodeRanges.All)
Returns
Type Parameters
T
ToBytes<T>(T)
Converts the object to json.
public static byte[] ToBytes<T>(T obj)
Parameters
objTThe object to convert
Returns
- byte[]
Type Parameters
TThe type to convert
ToObject<T>(JToken, string, JsonSerializerSettings?)
Converts a Json token to a typed object.
public static T? ToObject<T>(this JToken token, string domain, JsonSerializerSettings? settings = null)
Parameters
tokenJTokenThe token to deserialize
domainstringThe domain of the text.
settingsJsonSerializerSettingsThe settings of the deserializer. (default: Null)
Returns
- T
Type Parameters
TThe type to convert.
ToObject<T>(string, string, JsonSerializerSettings?)
Converts a Json object to a typed object.
public static T? ToObject<T>(string text, string domain, JsonSerializerSettings? settings = null)
Parameters
textstringThe text to deserialize
domainstringThe domain of the text.
settingsJsonSerializerSettingsThe settings of the deserializer. (default: Null)
Returns
- T
Type Parameters
TThe type to convert.
ToPrettyString<T>(T)
public static string ToPrettyString<T>(T obj)
Parameters
objT
Returns
Type Parameters
T
ToString<T>(T)
public static string ToString<T>(T obj)
Parameters
objT
Returns
Type Parameters
T
setupLoadSettings(bool)
public static void setupLoadSettings(bool ramOptimized)
Parameters
ramOptimizedbool