Class JsonValue
Represents a JSON value.
Inheritance
Implements
Inherited Members
Namespace: Manatee.Json
Assembly: Manatee.Json.dll
Syntax
public class JsonValue : IEquatable<JsonValue>
Remarks
A value can consist of a string, a numerical value, a boolean (true or false), a null placeholder, a JSON array of values, or a nested JSON object.
Constructors
| Improve this Doc View SourceJsonValue()
Creates a null JsonValue.
Declaration
public JsonValue()
JsonValue(JsonArray)
Creates a JsonValue from a JSON array.
Declaration
public JsonValue(JsonArray a)
Parameters
Type | Name | Description |
---|---|---|
JsonArray | a |
JsonValue(JsonObject)
Creates a JsonValue from a JSON object.
Declaration
public JsonValue(JsonObject o)
Parameters
Type | Name | Description |
---|---|---|
JsonObject | o |
JsonValue(JsonValue)
Creates a copy of a JsonValue.
Declaration
public JsonValue(JsonValue other)
Parameters
Type | Name | Description |
---|---|---|
JsonValue | other |
JsonValue(Boolean)
Creates a JsonValue from a boolean.
Declaration
public JsonValue(bool b)
Parameters
Type | Name | Description |
---|---|---|
System.Boolean | b |
JsonValue(Double)
Creates a JsonValue from a numeric value.
Declaration
public JsonValue(double n)
Parameters
Type | Name | Description |
---|---|---|
System.Double | n |
JsonValue(String)
Creates a JsonValue from a string.
Declaration
public JsonValue(string s)
Parameters
Type | Name | Description |
---|---|---|
System.String | s |
Fields
| Improve this Doc View SourceNull
Globally defined null-valued JSON value.
Declaration
public static readonly JsonValue Null
Field Value
Type | Description |
---|---|
JsonValue |
Remarks
When adding values to a JsonObject or JsonArray, nulls will automatically be converted into this field.
Properties
| Improve this Doc View SourceArray
Accesses the JsonValue as a JSON array.
Declaration
public JsonArray Array { get; }
Property Value
Type | Description |
---|---|
JsonArray |
Exceptions
Type | Condition |
---|---|
JsonValueIncorrectTypeException | Thrown when this JsonValue does not contain a Json array. |
Boolean
Accesses the JsonValue as a boolean.
Declaration
public bool Boolean { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
Exceptions
Type | Condition |
---|---|
JsonValueIncorrectTypeException | Thrown when this JsonValue does not contain a boolean. |
Number
Accesses the JsonValue as a numeric value.
Declaration
public double Number { get; }
Property Value
Type | Description |
---|---|
System.Double |
Exceptions
Type | Condition |
---|---|
JsonValueIncorrectTypeException | Thrown when this JsonValue does not contain a numeric value. |
Object
Accesses the JsonValue as a JSON object.
Declaration
public JsonObject Object { get; }
Property Value
Type | Description |
---|---|
JsonObject |
Exceptions
Type | Condition |
---|---|
JsonValueIncorrectTypeException | Thrown when this JsonValue does not contain a Json object. |
String
Accesses the JsonValue as a string.
Declaration
public string String { get; }
Property Value
Type | Description |
---|---|
System.String |
Remarks
Setting the value as a string will automatically change the JsonValue's type and discard the old data.
Exceptions
Type | Condition |
---|---|
JsonValueIncorrectTypeException | Thrown when this JsonValue does not contain a string. |
Type
Gets the value type of the existing data.
Declaration
public JsonValueType Type { get; }
Property Value
Type | Description |
---|---|
JsonValueType |
Methods
| Improve this Doc View SourceEquals(Nullable<JsonValue>)
Indicates whether the current object is equal to another object of the same type.
Declaration
public bool Equals(JsonValue? other)
Parameters
Type | Name | Description |
---|---|---|
System.Nullable<JsonValue> | other | An object to compare with this object. |
Returns
Type | Description |
---|---|
System.Boolean | true if the current object is equal to the |
Equals(Nullable<Object>)
Determines whether the specified System.Object is equal to the current System.Object.
Declaration
public override bool Equals(object? obj)
Parameters
Type | Name | Description |
---|---|---|
System.Nullable<System.Object> | obj | The System.Object to compare with the current System.Object. |
Returns
Type | Description |
---|---|
System.Boolean | true if the specified System.Object is equal to the current System.Object; otherwise, false. |
GetHashCode()
Serves as a hash function for a particular type.
Declaration
public override int GetHashCode()
Returns
Type | Description |
---|---|
System.Int32 | A hash code for the current System.Object. |
Overrides
GetIndentedString(Int32)
Creates a string representation of the JSON data.
Declaration
public string GetIndentedString(int indentLevel = 0)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | indentLevel | The indention level for the value. |
Returns
Type | Description |
---|---|
System.String | A string. |
Parse(TextReader)
Parses data from a System.IO.StreamReader containing a JSON value.
Declaration
public static JsonValue Parse(TextReader stream)
Parameters
Type | Name | Description |
---|---|---|
System.IO.TextReader | stream | the System.IO.StreamReader to parse. |
Returns
Type | Description |
---|---|
JsonValue | The JSON value represented by the System.String. |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | Thrown if |
System.ArgumentException | Thrown if |
JsonSyntaxException | Thrown if |
Parse(String)
Parses a System.String containing a JSON value.
Declaration
public static JsonValue Parse(string source)
Parameters
Type | Name | Description |
---|---|---|
System.String | source | the System.String to parse. |
Returns
Type | Description |
---|---|
JsonValue | The JSON value represented by the System.String. |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | Thrown if |
System.ArgumentException | Thrown if |
JsonSyntaxException | Thrown if |
ParseAsync(TextReader)
Parses data from a System.IO.StreamReader containing a JSON value.
Declaration
public static Task<JsonValue> ParseAsync(TextReader stream)
Parameters
Type | Name | Description |
---|---|---|
System.IO.TextReader | stream | the System.IO.StreamReader to parse. |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task<JsonValue> | The JSON value represented by the System.String. |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | Thrown if |
System.ArgumentException | Thrown if |
JsonSyntaxException | Thrown if |
ToString()
Creates a string that represents this JsonValue.
Declaration
public override string ToString()
Returns
Type | Description |
---|---|
System.String | A string representation of this JsonValue. |
Overrides
Remarks
Passing the returned string back into the parser will result in a copy of this JsonValue.
Operators
| Improve this Doc View SourceEquality(Nullable<JsonValue>, Nullable<JsonValue>)
Performs an equality comparison between two JsonValues.
Declaration
public static bool operator ==(JsonValue? a, JsonValue? b)
Parameters
Type | Name | Description |
---|---|---|
System.Nullable<JsonValue> | a | A JsonValue. |
System.Nullable<JsonValue> | b | A JsonValue. |
Returns
Type | Description |
---|---|
System.Boolean | true if the values are equal; otherwise, false. |
Implicit(Boolean to JsonValue)
Implicitly converts a System.Boolean into a JsonValue.
Declaration
public static implicit operator JsonValue(bool b)
Parameters
Type | Name | Description |
---|---|---|
System.Boolean | b | A System.Boolean. |
Returns
Type | Description |
---|---|
JsonValue | A JsonValue that represents the System.Boolean. |
Remarks
This is useful when creating an initialized JsonObject or JsonArray.
Examples
JsonObject obj = new JsonObject{
{"stringData", "string"},
{"numberData", 10.6},
{"boolData", true},
{"arrayData", new JsonArray{false, "Array String", JsonValue.Null, 8e-4}},
{"objectData", new JsonObject{
{"stringData2", "another string"},
{"moreBoolData", false}}}};
|
Improve this Doc
View Source
Implicit(Double to JsonValue)
Implicitly converts a System.Double into a JsonValue.
Declaration
public static implicit operator JsonValue(double n)
Parameters
Type | Name | Description |
---|---|---|
System.Double | n | A System.Double. |
Returns
Type | Description |
---|---|
JsonValue | A JsonValue that represents the System.Double. |
Remarks
This is useful when creating an initialized JsonObject or JsonArray.
Examples
JsonObject obj = new JsonObject{
{"stringData", "string"},
{"numberData", 10.6},
{"boolData", true},
{"arrayData", new JsonArray{false, "Array String", JsonValue.Null, 8e-4}},
{"objectData", new JsonObject{
{"stringData2", "another string"},
{"moreBoolData", false}}}};
|
Improve this Doc
View Source
Implicit(Nullable<JsonArray> to JsonValue)
Declaration
public static implicit operator JsonValue(JsonArray? a)
Parameters
Type | Name | Description |
---|---|---|
System.Nullable<JsonArray> | a | A JSON array. |
Returns
Type | Description |
---|---|
JsonValue |
Remarks
This is useful when creating an initialized JsonObject or JsonArray.
Examples
JsonObject obj = new JsonObject{
{"stringData", "string"},
{"numberData", 10.6},
{"boolData", true},
{"arrayData", new JsonArray{false, "Array String", JsonValue.Null, 8e-4}},
{"objectData", new JsonObject{
{"stringData2", "another string"},
{"moreBoolData", false}}}};
|
Improve this Doc
View Source
Implicit(Nullable<JsonObject> to JsonValue)
Implicitly converts a JsonObject into a JsonValue.
Declaration
public static implicit operator JsonValue(JsonObject? o)
Parameters
Type | Name | Description |
---|---|---|
System.Nullable<JsonObject> | o | A JSON object. |
Returns
Type | Description |
---|---|
JsonValue | A JsonValue that represents the JsonObject. |
Remarks
This is useful when creating an initialized JsonObject or JsonArray.
Examples
JsonObject obj = new JsonObject{
{"stringData", "string"},
{"numberData", 10.6},
{"boolData", true},
{"arrayData", new JsonArray{false, "Array String", JsonValue.Null, 8e-4}},
{"objectData", new JsonObject{
{"stringData2", "another string"},
{"moreBoolData", false}}}};
|
Improve this Doc
View Source
Implicit(Nullable<String> to JsonValue)
Implicitly converts a System.String into a JsonValue.
Declaration
public static implicit operator JsonValue(string? s)
Parameters
Type | Name | Description |
---|---|---|
System.Nullable<System.String> | s | A System.String. |
Returns
Type | Description |
---|---|
JsonValue | A JsonValue that represents the System.String. |
Remarks
This is useful when creating an initialized JsonObject or JsonArray.
Examples
JsonObject obj = new JsonObject{
{"stringData", "string"},
{"numberData", 10.6},
{"boolData", true},
{"arrayData", new JsonArray{false, "Array String", JsonValue.Null, 8e-4}},
{"objectData", new JsonObject{
{"stringData2", "another string"},
{"moreBoolData", false}}}};
|
Improve this Doc
View Source
Inequality(Nullable<JsonValue>, Nullable<JsonValue>)
Performs an inverted equality comparison between two JsonValues.
Declaration
public static bool operator !=(JsonValue? a, JsonValue? b)
Parameters
Type | Name | Description |
---|---|---|
System.Nullable<JsonValue> | a | A JsonValue. |
System.Nullable<JsonValue> | b | A JsonValue. |
Returns
Type | Description |
---|---|
System.Boolean | false if the values are equal; otherwise, true. |