Class JsonHelpers
JSON reading and writing utilities.
public static class JsonHelpers
- Inheritance
-
JsonHelpers
- Inherited Members
Fields
Options
The default JSON serialisation options.
public static readonly JsonSerializerOptions Options
Field Value
Methods
Create(JsonSerializerOptions)
Creates a JsonSerializerOptions which has the basic
properties of Options, but the converters of options
.
public static JsonSerializerOptions Create(JsonSerializerOptions options)
Parameters
options
JsonSerializerOptions
Returns
LoadFrom<T>(string)
Reads JSON data from path
and returns it as a/an T
.
public static T? LoadFrom<T>(string path) where T : class
Parameters
path
string
Returns
- T
true
on success,false
if the file cannot be found.
Type Parameters
T
LoadFrom<T>(string, JsonSerializerOptions)
Reads JSON data from path
and returns it as a/an T
.
Also uses custom JSON serialisation options.
public static T? LoadFrom<T>(string path, JsonSerializerOptions options) where T : class
Parameters
path
stringoptions
JsonSerializerOptions
Returns
- T
true
on success,false
if the file cannot be found.
Type Parameters
T
LoadFrom<T>(ref T, string)
Reads JSON data from path
and stores it into
outObject
.
public static bool LoadFrom<T>(ref T outObject, string path) where T : struct
Parameters
outObject
Tpath
string
Returns
- bool
true
on success,false
if the file cannot be found.
Type Parameters
T
LoadFrom<T>(ref T, string, JsonSerializerOptions)
Reads JSON data from path
and stores it into
outObject
. Uses custom options also.
public static bool LoadFrom<T>(ref T outObject, string path, JsonSerializerOptions options) where T : struct
Parameters
outObject
Tpath
stringoptions
JsonSerializerOptions
Returns
- bool
true
on success,false
if the file cannot be found.
Type Parameters
T
Write<T>(T, string)
Writes what
into a file path
.
public static bool Write<T>(T what, string path)
Parameters
what
Tpath
string
Returns
- bool
true
on success,false
if the path is invalid.
Type Parameters
T