Skip to content

JTokenExtensionsGet

robbyxp1 edited this page Feb 9, 2025 · 13 revisions

JTokenExtensionsGet Class

Extension class helpers for converting a JToken safely to a c# class.
Null may be passed as the JToken and it will return the default given in the converter
ie. token["propertyname"].Str("default") works safely even if propertyname does not exist.

public static class JTokenExtensionsGet

Inheritance System.Object 🡒 JTokenExtensionsGet


Methods


JTokenExtensionsGet.Array(JToken) Method

Convert token to JArray

public static QuickJSON.JArray Array(this QuickJSON.JToken token);
Parameters

token JToken

Returns

JArray


JTokenExtensionsGet.BigInteger(JToken, BigInteger) Method

Return a Big Integer. Return def if token is not present, not a number or null

public static System.Numerics.BigInteger BigInteger(this QuickJSON.JToken token, System.Numerics.BigInteger def);
Parameters

token JToken

def System.Numerics.BigInteger

Returns

System.Numerics.BigInteger


JTokenExtensionsGet.BigIntegerNull(JToken) Method

Return a Big Integer. Return null if token is not present, not a number or null

public static System.Nullable<System.Numerics.BigInteger> BigIntegerNull(this QuickJSON.JToken token);
Parameters

token JToken

Returns

System.Nullable<System.Numerics.BigInteger>


JTokenExtensionsGet.Bool(JToken, bool) Method

Return a bool. Return def if token is not present, not a number or null

public static bool Bool(this QuickJSON.JToken token, bool def=false);
Parameters

token JToken

def System.Boolean

Returns

System.Boolean


JTokenExtensionsGet.BoolNull(JToken) Method

Return an integer. Return null if token is not present, not a number or null

public static System.Nullable<bool> BoolNull(this QuickJSON.JToken token);
Parameters

token JToken

Returns

System.Nullable<System.Boolean>


JTokenExtensionsGet.DateTime(JToken, DateTime, CultureInfo, DateTimeStyles) Method

Return a DateTime with the parse of the string JToken.

public static System.DateTime DateTime(this QuickJSON.JToken token, System.DateTime def, System.Globalization.CultureInfo cultureinfo, System.Globalization.DateTimeStyles datetimestyle=System.Globalization.DateTimeStyles.AdjustToUniversal|System.Globalization.DateTimeStyles.AssumeUniversal);
Parameters

token JToken
Token to convert. Must be a string. May be null.

def System.DateTime
Default time if conversion fails

cultureinfo System.Globalization.CultureInfo
Culture

datetimestyle System.Globalization.DateTimeStyles
Convert style

Returns

System.DateTime
DateTime


JTokenExtensionsGet.DateTime(JToken, CultureInfo, DateTimeStyles) Method

Return a nullable DateTime with the parse of the string JToken.

public static System.Nullable<System.DateTime> DateTime(this QuickJSON.JToken token, System.Globalization.CultureInfo cultureinfo, System.Globalization.DateTimeStyles datetimestyle=System.Globalization.DateTimeStyles.AdjustToUniversal|System.Globalization.DateTimeStyles.AssumeUniversal);
Parameters

token JToken
Token to convert. Must be a string. May be null.

cultureinfo System.Globalization.CultureInfo
Culture

datetimestyle System.Globalization.DateTimeStyles
Convert style

Returns

System.Nullable<System.DateTime>
DateTime, or null if can't convert


JTokenExtensionsGet.DateTimeUTC(JToken) Method

Return a DateTime presuming UTC with the parse of the string JToken.

public static System.DateTime DateTimeUTC(this QuickJSON.JToken token);
Parameters

token JToken
Token to convert. Must be a string. May be null.

Returns

System.DateTime
DateTime with Kind=UTC, or DateTime.MinValue (with Kind=UTC) if conversion fails


JTokenExtensionsGet.DateTimeUTC(JToken, DateTime) Method

Return a DateTime presuming UTC with the parse of the string JToken.

public static System.DateTime DateTimeUTC(this QuickJSON.JToken token, System.DateTime def);
Parameters

token JToken
Token to convert. Must be a string. May be null.

def System.DateTime
Default time if conversion fails. Converted to UTC

Returns

System.DateTime
DateTime with Kind=UTC, or def (with Kind=UTC) if conversion fails


JTokenExtensionsGet.Double(JToken, double) Method

Return a double. Return def if token is not present, not a number or null

public static double Double(this QuickJSON.JToken token, double def=0.0);
Parameters

token JToken

def System.Double

Returns

System.Double


JTokenExtensionsGet.Double(JToken, double, double) Method

Return a float with scaling. Return def if token is not present, not a number or null.

public static double Double(this QuickJSON.JToken token, double scale, double def);
Parameters

token JToken

scale System.Double

def System.Double

Returns

System.Double


JTokenExtensionsGet.DoubleNull(JToken) Method

Return a double. Return null if token is not present, not a number or null

public static System.Nullable<double> DoubleNull(this QuickJSON.JToken token);
Parameters

token JToken

Returns

System.Nullable<System.Double>


JTokenExtensionsGet.DoubleNull(JToken, double) Method

Return a double with scaling. Return null if token is not present, not a number or null

public static System.Nullable<double> DoubleNull(this QuickJSON.JToken token, double scale);
Parameters

token JToken

scale System.Double

Returns

System.Nullable<System.Double>


JTokenExtensionsGet.Enum<T>(JToken, T) Method

Return the enumeration of T from a JToken Long representation of the value of the enumeration. Return def if token is not present, null or not a long

public static T Enum<T>(this QuickJSON.JToken token, T def);
Type parameters

T
Enumeration type to use

Parameters

token JToken

def T

Returns

T


JTokenExtensionsGet.Enumeration<T>(JToken, T, Func<string,string>) Method

Convert a string token to an enumeration of type T. Return def if conversion fails

public static T Enumeration<T>(this QuickJSON.JToken token, T def, System.Func<string,string> preprocess=null);
Type parameters

T
Enumeration type to convert

Parameters

token JToken
Token to convert. Must be a string. May be null.

def T
Default enumeration value

preprocess System.Func<System.String,System.String>
Function to call to preprocess the string before conversion. May be null

Returns

T
Enumeration, or def if converstion fails.


JTokenExtensionsGet.EnumStr<T>(JToken, T, bool) Method

Return the enumeration of T from a JToken string representation of the value of the enumeration. Return def if token is not present, null or not a string.

public static T EnumStr<T>(this QuickJSON.JToken token, T def, bool ignorecase=true)
    where T : struct;
Type parameters

T
Enumeration type to use

Parameters

token JToken

def T

ignorecase System.Boolean

Returns

T


JTokenExtensionsGet.Float(JToken, float) Method

Return a float. Return def if token is not present, not a number or null

public static float Float(this QuickJSON.JToken token, float def=0f);
Parameters

token JToken

def System.Single

Returns

System.Single


JTokenExtensionsGet.Float(JToken, float, float) Method

Return a float with scaling. Return def if token is not present, not a number or null.

public static float Float(this QuickJSON.JToken token, float scale, float def);
Parameters

token JToken

scale System.Single

def System.Single

Returns

System.Single


JTokenExtensionsGet.FloatNull(JToken) Method

Return a float. Return null if token is not present, not a number or null

public static System.Nullable<float> FloatNull(this QuickJSON.JToken token);
Parameters

token JToken

Returns

System.Nullable<System.Single>


JTokenExtensionsGet.FloatNull(JToken, float) Method

Return a float with scale. Return null if token is not present, not a number or null

public static System.Nullable<float> FloatNull(this QuickJSON.JToken token, float scale);
Parameters

token JToken

scale System.Single

Returns

System.Nullable<System.Single>


JTokenExtensionsGet.I(JToken, object) Method

Index into JObject or JArray safely

public static QuickJSON.JToken I(this QuickJSON.JToken token, object id);
Parameters

token JToken

id System.Object

Returns

JToken


JTokenExtensionsGet.Int(JToken, int) Method

Return an integer. Return def if token is not present, not a number or null

public static int Int(this QuickJSON.JToken token, int def=0);
Parameters

token JToken

def System.Int32

Returns

System.Int32


JTokenExtensionsGet.IntNull(JToken) Method

Return an integer. Return null if token is not present, not a number or null

public static System.Nullable<int> IntNull(this QuickJSON.JToken token);
Parameters

token JToken

Returns

System.Nullable<System.Int32>


JTokenExtensionsGet.IsNull(JToken) Method

Is token null or JToken Null

public static bool IsNull(this QuickJSON.JToken token);
Parameters

token JToken

Returns

System.Boolean


JTokenExtensionsGet.Long(JToken, long) Method

Return a long. Return def if token is not present, not a number or null

public static long Long(this QuickJSON.JToken token, long def=0L);
Parameters

token JToken

def System.Int64

Returns

System.Int64


JTokenExtensionsGet.LongNull(JToken) Method

Return a long. Return null if token is not present, not a number or null

public static System.Nullable<long> LongNull(this QuickJSON.JToken token);
Parameters

token JToken

Returns

System.Nullable<System.Int64>


JTokenExtensionsGet.MultiStr(JObject, string, string[]) Method

Return a string looking for this list of property names. Return def if not found or not string
This one you must supply def but you can use the params array syntax with

public static string MultiStr(this QuickJSON.JObject token, string def, params string[] propertynameslist);
Parameters

token JObject

def System.String

propertynameslist System.String[]

Returns

System.String


JTokenExtensionsGet.MultiStr(JObject, string[], string) Method

Return a string looking for this list of property names. Return def if not found or not string

public static string MultiStr(this QuickJSON.JObject token, string[] propertynameslist, string def="");
Parameters

token JObject

propertynameslist System.String[]

def System.String

Returns

System.String


JTokenExtensionsGet.Object(JToken) Method

Convert token to JObject

public static QuickJSON.JObject Object(this QuickJSON.JToken token);
Parameters

token JToken

Returns

JObject


JTokenExtensionsGet.Str(JToken, string) Method

Return a string from the token. Return def if null or not a string

public static string Str(this QuickJSON.JToken token, string def="");
Parameters

token JToken

def System.String

Returns

System.String


JTokenExtensionsGet.StrNull(JToken) Method

Return a string from the token. Return null if not string

public static string StrNull(this QuickJSON.JToken token);
Parameters

token JToken

Returns

System.String


JTokenExtensionsGet.TryGetBool(JToken, bool) Method

Try and get a bool

public static bool TryGetBool(this QuickJSON.JToken token, out bool value);
Parameters

token JToken
token

value System.Boolean
bool return

Returns

System.Boolean
true if token is not null and is an value which can convert to an bool


JTokenExtensionsGet.TryGetDouble(JToken, double) Method

Try and get an double

public static bool TryGetDouble(this QuickJSON.JToken token, out double value);
Parameters

token JToken
token

value System.Double
double return

Returns

System.Boolean
true if token is not null and is an value which can convert to an double


JTokenExtensionsGet.TryGetFloat(JToken, float) Method

Try and get a float

public static bool TryGetFloat(this QuickJSON.JToken token, out float value);
Parameters

token JToken
token

value System.Single
float return

Returns

System.Boolean
true if token is not null and is an value which can convert to an float


JTokenExtensionsGet.TryGetInt(JToken, int) Method

Try and get an integer

public static bool TryGetInt(this QuickJSON.JToken token, out int value);
Parameters

token JToken
token

value System.Int32
integer return

Returns

System.Boolean
true if token is not null and is an value which can convert to an integer


JTokenExtensionsGet.TryGetLong(JToken, long) Method

Try and get an integer

public static bool TryGetLong(this QuickJSON.JToken token, out long value);
Parameters

token JToken
token

value System.Int64
integer return

Returns

System.Boolean
true if token is not null and is an value which can convert to an integer


JTokenExtensionsGet.TryGetUInt(JToken, uint) Method

Try and get an integer

public static bool TryGetUInt(this QuickJSON.JToken token, out uint value);
Parameters

token JToken
token

value System.UInt32
integer return

Returns

System.Boolean
true if token is not null and is an value which can convert to an integer


JTokenExtensionsGet.TryGetULong(JToken, ulong) Method

Try and get an integer

public static bool TryGetULong(this QuickJSON.JToken token, out ulong value);
Parameters

token JToken
token

value System.UInt64
integer return

Returns

System.Boolean
true if token is not null and is an value which can convert to an integer


JTokenExtensionsGet.UInt(JToken, uint) Method

Return an unsigned integer. Return def if token is not present, not a number or null

public static uint UInt(this QuickJSON.JToken token, uint def=0u);
Parameters

token JToken

def System.UInt32

Returns

System.UInt32


JTokenExtensionsGet.UIntNull(JToken) Method

Return an unsigned integer. Return null if token is not present, not a number or null

public static System.Nullable<uint> UIntNull(this QuickJSON.JToken token);
Parameters

token JToken

Returns

System.Nullable<System.UInt32>


JTokenExtensionsGet.ULong(JToken, ulong) Method

Return an unsigned long. Return def if token is not present, not a number or null

public static ulong ULong(this QuickJSON.JToken token, ulong def=0uL);
Parameters

token JToken

def System.UInt64

Returns

System.UInt64


JTokenExtensionsGet.ULongNull(JToken) Method

Return an unsigned long. Return null if token is not present, not a number or null

public static System.Nullable<ulong> ULongNull(this QuickJSON.JToken token);
Parameters

token JToken

Returns

System.Nullable<System.UInt64>

Clone this wiki locally