Json​Value Json​Value Json​Value Class

Definition

Implements the IJsonValue interface which represents a JSON value.

A JsonValue object can represent the three primitive JSON value types of Boolean, Number and String, and can also represent the complex value types of Array and Object by providing ways to access them.

public sealed class JsonValue : IJsonValue, IStringablepublic sealed class JsonValue : IJsonValue, IStringablePublic NotInheritable Class JsonValue Implements IJsonValue, IStringable
Attributes
Windows 10 requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)

Remarks

A JsonValue object has overloaded constructors to instantiate a new object from a JSON String, Number or Boolean value and a default constructor that instantiates a JsonValue object with a ValueType of NULL.

For an example of how these class methods are used to parse a number or string from a JSON string and convert it into a JsonValue object, see Using JavaScript Object Notation (JSON).

Properties

ValueType ValueType ValueType

Gets the type of the encapsulated JSON value. Possible types are defined by JsonValueType.

public JsonValueType ValueType { get; }public JsonValueType ValueType { get; }Public ReadOnly Property ValueType As JsonValueType
Value
JsonValueType JsonValueType JsonValueType

The JSON value type.

Attributes

Methods

CreateBooleanValue(Boolean) CreateBooleanValue(Boolean) CreateBooleanValue(Boolean)

Creates a JsonValue from a Boolean.

public static JsonValue CreateBooleanValue(Boolean input)public static JsonValue CreateBooleanValue(Boolean input)Public Static Function CreateBooleanValue(input As Boolean) As JsonValue
Parameters
input
System.Boolean System.Boolean System.Boolean

The value to store in the JsonValue.

Returns
Attributes

CreateNullValue() CreateNullValue() CreateNullValue()

Creates a JsonValue with a NULL value.

public static JsonValue CreateNullValue()public static JsonValue CreateNullValue()Public Static Function CreateNullValue() As JsonValue
Returns

The JsonValue with a NULL value.

Attributes

CreateNumberValue(Double) CreateNumberValue(Double) CreateNumberValue(Double)

Creates a JsonValue from a Number (Double).

public static JsonValue CreateNumberValue(Double input)public static JsonValue CreateNumberValue(Double input)Public Static Function CreateNumberValue(input As Double) As JsonValue
Parameters
input
System.Double System.Double System.Double

The Number to store in the JsonValue.

Returns
Attributes

CreateStringValue(String) CreateStringValue(String) CreateStringValue(String)

Creates the string for a JsonValue.

public static JsonValue CreateStringValue(String input)public static JsonValue CreateStringValue(String input)Public Static Function CreateStringValue(input As String) As JsonValue
Parameters
input
System.String System.String System.String

The string for the JsonValue.

Returns
Attributes

GetArray() GetArray() GetArray()

Gets an array if the ValueType of the encapsulated value is Array.

public JsonArray GetArray()public JsonArray GetArray()Public Function GetArray() As JsonArray
Returns
Attributes

GetBoolean() GetBoolean() GetBoolean()

Gets the Boolean if the ValueType of the encapsulated value is Boolean.

public bool GetBoolean()public bool GetBoolean()Public Function GetBoolean() As bool
Returns
bool bool bool

The Boolean value.

Attributes

GetNumber() GetNumber() GetNumber()

Gets the number (a Double) if the ValueType of the encapsulated value is Number.

public double GetNumber()public double GetNumber()Public Function GetNumber() As double
Returns
double double double

The number value.

Attributes

GetObject() GetObject() GetObject()

Gets a JsonObject if the ValueType of the encapsulated value is Object.

public JsonObject GetObject()public JsonObject GetObject()Public Function GetObject() As JsonObject
Returns
Attributes

GetString() GetString() GetString()

Gets a String if the ValueType of the encapsulated value is String.

public string GetString()public string GetString()Public Function GetString() As string
Returns
string string string

The String value.

Attributes

Parse(String) Parse(String) Parse(String)

Parses the specified JSON string into a JsonValue.

Note

This method will throw an exception if the provided JSON string is not valid. Use of JsonObject.TryParse is a recommended alternative. A TryParse call will return a boolean value to indicate success or failure and, if successful, the resultant JsonValue.

public static JsonValue Parse(String input)public static JsonValue Parse(String input)Public Static Function Parse(input As String) As JsonValue
Parameters
input
System.String System.String System.String

The specified JSON string.

Returns
Attributes

Remarks

This method may only be called when the ValueType is Null. If the value contained in the specified JSON string is a String, a Number or a Boolean, the ValueType will be updated and the actual value can then be accessed through the GetString, GetNumber or GetBoolean methods. If Parse fails due to an invalid JSON string or resource allocation errors, the ValueType will not be changed.

When implemented on the subclass @Windows.Data.Json.JsonObject.#ctor?text=JsonObject, this method requires the specified input string to be a valid JSON object value. When implemented on the subclass @Windows.Data.Json.JsonArray.#ctor?text=JsonArray, this method requires the specified input string to be a valid JSON array value. The original object state will be overwritten when @Windows.Data.Json.JsonObject.#ctor?text=JsonObject.@Windows.Data.Json.JsonValue.Parse(System.String)?text=Parse or @Windows.Data.Json.JsonArray.#ctor?text=JsonArray.@Windows.Data.Json.JsonValue.Parse(System.String)?text=Parse succeeds. If Parse fails, the object state remains intact.

Stringify() Stringify() Stringify()

Retrieves the JSON representation of the encapsulated value.

public string Stringify()public string Stringify()Public Function Stringify() As string
Returns
string string string

A JSON representation of the encapsulated value.

Attributes

Remarks

If the ValueType is String, then the returned string will be properly escaped and double quoted. This method is used for serializing the encapsulated value into a valid JSON format.

ToString() ToString() ToString()

Retrieves the JSON representation of the encapsulated value.

public string ToString()public string ToString()Public Function ToString() As string
Returns
string string string

A JSON representation of the encapsulated value.

Attributes

Remarks

If the ValueType is String, then the returned string will be properly escaped and double quoted. This method is used for serializing the encapsulated value into a valid JSON format.

TryParse(String, JsonValue) TryParse(String, JsonValue) TryParse(String, JsonValue)

Parses the specified string into a JsonValue.

public static bool TryParse(String input, JsonValue result)public static bool TryParse(String input, JsonValue result)Public Static Function TryParse(input As String, result As JsonValue) As bool
Parameters
input
System.String System.String System.String

The specified string.

result
JsonValue JsonValue JsonValue

The new JsonValue object.

Returns
bool bool bool

True if the JsonValue object was successfully created; otherwise, false.

Attributes

See Also