Legend

Class
Struct
Enum
Interface
Delegate
Constructor
Method
Property
Event
Field

Abstract class: RT.Json.JsonNumber

Summary

Encapsulates a number, which may be a floating-point number or an integer, as a JsonValue. See Remarks.

Remarks

JSON does not define any specific limits for numeric values. This implementation supports integers in the signed and unsigned 64-bit range, as well as IEEE 64-bit doubles (except NaNs and infinities). Conversions to/from decimal are exact for integers, but can be approximate for non-integers, depending on the exact value.

Instance methods

void Add the specified item to the current list if it is a JsonList; otherwise, throws.
void
Add(string key, JsonValue value)
Adds the specified key/value pair to the dictionary if this is a JsonDict; otherwise, throws.
void
AddRange(IEnumerable<KeyValuePair<string, JsonValue>> items)
Add the specified items to the current dictionary if it is a JsonDict; otherwise, throws.
void
AddRange(IEnumerable<JsonValue> items)
Add the specified items to the current list if it is a JsonList; otherwise, throws.
void
AppendIndented(StringBuilder sb, int indentation = 0)
Converts the current JSON value to a JSON void that parses back to this value and places the string into the specified StringBuilder.
void Removes all items from the current value if it is a JsonList or JsonDict; otherwise, throws.
bool Determines whether the specified item is contained in the current list if it is a JsonList; otherwise, throws.
bool
ContainsKey(string key)
Determines whether an entry with the specified key exists in the dictionary if this is a JsonDict; otherwise, throws.
void
CopyTo(JsonValue[] array, int arrayIndex)
Copies the entire list to a compatible one-dimensional array, starting at the specified arrayIndex of the target array, if this is a JsonList; otherwise, throws.
bool
Equals(object other)
  • Overrides: object.Equals(object)
See JsonValue.Equals(JsonValue).
bool
bool
boolConverts the current value to a bool. Throws if the conversion is not valid.
bool Converts the current value to a bool by using the BoolConversionOptions.Lenient option. Throws if the conversion is not valid.
bool? Converts the current value to a bool by using the BoolConversionOptions.Lenient option. Returns null if the conversion is not valid.
bool?Converts the current value to a bool. Returns null if the conversion is not valid.
decimalConverts the current value to a decimal. Throws if the conversion is not valid.
decimal Converts the current value to a decimal by using the NumericConversionOptions.Lenient option. Throws if the conversion is not valid.
decimal? Converts the current value to a decimal by using the NumericConversionOptions.Lenient option. Returns null if the conversion is not valid.
decimal?Converts the current value to a decimal. Returns null if the conversion is not valid.
JsonDict Converts the current value to JsonDict if it is a JsonDict; otherwise, throws.
JsonDict Converts the current value to JsonDict if it is a JsonDict; otherwise, returns null.
doubleConverts the current value to a double. Throws if the conversion is not valid.
double Converts the current value to a double by using the NumericConversionOptions.Lenient option. Throws if the conversion is not valid.
double? Converts the current value to a double by using the NumericConversionOptions.Lenient option. Returns null if the conversion is not valid.
double?Converts the current value to a double. Returns null if the conversion is not valid.
int
  • Overrides: object.GetHashCode()
  • Abstract
Overrides object.GetHashCode.
intConverts the current value to an int. Throws if the conversion is not valid.
int Converts the current value to an int by using the NumericConversionOptions.Lenient option. Throws if the conversion is not valid.
int? Converts the current value to an int by using the NumericConversionOptions.Lenient option. Returns null if the conversion is not valid.
int?Converts the current value to an int. Returns null if the conversion is not valid.
JsonList Converts the current value to JsonList if it is a JsonList; otherwise, throws.
JsonList Converts the current value to JsonList if it is a JsonList; otherwise, returns null.
longConverts the current value to a long. Throws if the conversion is not valid.
long Converts the current value to a long by using the NumericConversionOptions.Lenient option. Throws if the conversion is not valid.
long? Converts the current value to a long by using the NumericConversionOptions.Lenient option. Returns null if the conversion is not valid.
long?Converts the current value to a long. Returns null if the conversion is not valid.
stringConverts the current value to a string. Throws if the conversion is not valid.
string Converts the current value to a string by using the StringConversionOptions.Lenient option. Throws if the conversion is not valid.
string Converts the current value to a string by using the StringConversionOptions.Lenient option. Returns null if the conversion is not valid.
stringConverts the current value to a string. Returns null if the conversion is not valid.
ulongConverts the current value to a ulong. Throws if the conversion is not valid.
ulong Converts the current value to a ulong by using the NumericConversionOptions.Lenient option. Throws if the conversion is not valid.
ulong? Converts the current value to a ulong by using the NumericConversionOptions.Lenient option. Returns null if the conversion is not valid.
ulong?Converts the current value to a ulong. Returns null if the conversion is not valid.
int Returns the index of the first occurrence of the specified item within the current list if it is a JsonList; otherwise, throws.
void
Insert(int index, JsonValue item)
Inserts the specified item at the specified index to the current list if it is a JsonList; otherwise, throws.
bool
Remove(string key)
Removes the entry with the specified key from the dictionary if this is a JsonDict; otherwise, throws.
bool Removes the first instance of the specified item from the current list if it is a JsonList; otherwise, throws.
void
RemoveAt(int index)
Removes the item at the specified index from the current list if it is a JsonList; otherwise, throws.
IEnumerable<string>See JsonValue.ToEnumerable().
string
  • Inherited from JsonValue
  • Overrides: object.ToString()
Converts the current JSON value to a JSON string that parses back to this value.
string
bool
TryGetValue(string key, out JsonValue value)
Attempts to retrieve the value associated with the specified key if this is a JsonDict; otherwise, throws.

Static methods

void
AppendIndented(JsonValue value, StringBuilder sb, int indentation = 0)
Converts the JSON value to a JSON string that parses back to this value and places the string into the specified StringBuilder. Supports null values.
JsonNumber
Create(double value)
Constructs a JsonNumber from the specified double-precision floating-point number.
JsonNumber
Create(long value)
Constructs a JsonNumber from the specified 64-bit integer.
JsonNumber
Create(ulong value)
Constructs a JsonNumber from the specified unsigned 64-bit integer.
JsonNumber
Create(int value)
Constructs a JsonNumber from the specified 32-bit integer.
JsonNumber
Create(decimal value)
Constructs a JsonNumber from the specified decimal. This operation is slightly lossy; see Remarks on JsonNumber.
string
Fmt(string js, params JsonValue[] namevalues)
Formats JSON values into a piece of JavaScript code and then removes almost all unnecessary whitespace and comments. Values are referenced by names; placeholders for these values are written as {{name}}. Placeholders are only replaced outside of JavaScript literal strings and regexes. JsonRaw instances are inserted unmodified.
JsonNumber
Parse(string jsonNumber, bool allowJavaScript = false)
Parses the specified JSON as a JSON number. All other types of JSON values result in a JsonParseException.
IEnumerable<string>Lazy-converts the JSON value to a JSON string that parses back to this value. Supports null values.
stringConverts the JSON value to a JSON string that parses back to this value. Supports null values.
string
bool
TryParse(string jsonNumber, out JsonNumber result)
Attempts to parse the specified string into a JSON number.
bool
TryParse(string jsonValue, out JsonValue result)
Attempts to parse the specified string into a JSON value.

Operators

JsonNumber Converts the specified decimal to a JsonNumber value. This operator is slightly lossy; see Remarks on JsonNumber.
JsonNumber Converts the specified nullable decimal to a JsonNumber value. This operator is slightly lossy; see Remarks on JsonNumber.
stringSee StringConversionOptions.Strict.
boolSee BoolConversionOptions.Strict.
bool?
doubleSee NumericConversionOptions.Strict.
double?
decimal
decimal?
long
long?
ulong
ulong?
int
int?
string[]See StringConversionOptions.Strict.
bool[]See BoolConversionOptions.Strict.
bool?[]
double[]See NumericConversionOptions.Strict.
double?[]
decimal[]
decimal?[]
long[]
long?[]
ulong[]
ulong?[]
int[]
int?[]
List<string>See StringConversionOptions.Strict.
List<bool>See BoolConversionOptions.Strict.
List<bool?>
List<double>See NumericConversionOptions.Strict.
List<double?>
List<decimal>
List<decimal?>
List<long>
List<long?>
List<ulong>
List<ulong?>
List<int>
List<int?>
JsonNumberConverts the specified double to a JsonNumber value.
JsonNumberConverts the specified nullable double to a JsonNumber value.
JsonNumberConverts the specified unsigned 64-bit integer to a JsonNumber value.
JsonNumberConverts the specified nullable unsigned 64-bit integer to a JsonNumber value.
JsonNumberConverts the specified 64-bit integer to a JsonNumber value.
JsonNumberConverts the specified nullable 64-bit integer to a JsonNumber value.
JsonNumberConverts the specified 32-bit integer to a JsonNumber value.
JsonNumberConverts the specified nullable 32-bit integer to a JsonNumber value.
JsonValueConstructs a JsonValue from the specified string.
JsonValueConstructs a JsonValue from the specified boolean.
JsonValueConstructs a JsonValue from the specified nullable boolean.
JsonValueConstructs a JsonValue from the specified double.
JsonValueConstructs a JsonValue from the specified nullable double.
JsonValueConstructs a JsonValue from the specified decimal.
JsonValueConstructs a JsonValue from the specified nullable decimal.
JsonValueConstructs a JsonValue from the specified long.
JsonValueConstructs a JsonValue from the specified nullable long.
JsonValueConstructs a JsonValue from the specified ulong.
JsonValueConstructs a JsonValue from the specified nullable ulong.
JsonValueConstructs a JsonValue from the specified int.
JsonValueConstructs a JsonValue from the specified nullable int.
JsonValueConstructs a JsonValue from the specified array.
JsonValue
JsonValue
JsonValue
JsonValue
implicit operator JsonValue(double?[] values)
JsonValue
implicit operator JsonValue(decimal[] values)
JsonValue
implicit operator JsonValue(decimal?[] values)
JsonValue
JsonValue
JsonValue
JsonValue
JsonValue
JsonValue
JsonValue
implicit operator JsonValue(JsonValue[] values)
JsonValue
implicit operator JsonValue(List<string> values)
Constructs a JsonValue from the specified list.
JsonValue
implicit operator JsonValue(List<bool> values)
JsonValue
implicit operator JsonValue(List<bool?> values)
JsonValue
implicit operator JsonValue(List<double> values)
JsonValue
implicit operator JsonValue(List<double?> values)
JsonValue
implicit operator JsonValue(List<decimal> values)
JsonValue
implicit operator JsonValue(List<decimal?> values)
JsonValue
implicit operator JsonValue(List<long> values)
JsonValue
implicit operator JsonValue(List<long?> values)
JsonValue
implicit operator JsonValue(List<ulong> values)
JsonValue
implicit operator JsonValue(List<ulong?> values)
JsonValue
implicit operator JsonValue(List<int> values)
JsonValue
implicit operator JsonValue(List<int?> values)
JsonValue

Instance properties

int Returns the number of items in the current value if it is a JsonList or JsonDict; otherwise, throws.
bool Returns true if this value is a JsonDict or a JsonList; otherwise, returns false.
JsonValue
this[int index]
Returns the item at the specified index within the current list if it is a JsonList; otherwise, throws.
JsonValue
this[string key]
Gets or sets the value associated with the specified key if this value is a JsonDict; otherwise, throws.
ICollection<string>Returns the keys contained in the dictionary if this is a JsonDict; otherwise, throws.
object
  • Abstract
Returns the value of this number as either a double, a long or a ulong.
JsonSafeValue Returns an object that allows safe access to the indexers. “Safe” in this context means that the indexers, when given an index or key not found in the list or dictionary, do not throw but instead return JsonNoValue.Instance whose getters (such as JsonValue.GetString(StringConversionOptions)) return null.
ICollection<JsonValue>Returns the values contained in the dictionary if this is a JsonDict; otherwise, throws.