JsonValue JsonValue JsonValue JsonValue 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, IStringable
public sealed class JsonValue : IJsonValue, IStringable
Public NotInheritable Class JsonValue Implements IJsonValue, IStringable
// This class does not provide a public constructor.
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 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
var jsonValueType = jsonValue.valueType;

Methods

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

Creates a JsonValue from a Boolean.

public : static JsonValue CreateBooleanValue(bool input)
public static JsonValue CreateBooleanValue(Boolean input)
Public Static Function CreateBooleanValue(input As Boolean) As JsonValue
var jsonValue = Windows.Data.Json.JsonValue.createBooleanValue(input);
Parameters
input
bool Boolean Boolean Boolean

The value to store in the JsonValue.

Returns

CreateNullValue() CreateNullValue() CreateNullValue() CreateNullValue()

Creates a JsonValue with a NULL value.

public : static JsonValue CreateNullValue()
public static JsonValue CreateNullValue()
Public Static Function CreateNullValue() As JsonValue
var jsonValue = Windows.Data.Json.JsonValue.createNullValue();
Returns

CreateNumberValue(Double) 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
var jsonValue = Windows.Data.Json.JsonValue.createNumberValue(input);
Parameters
input
double Double Double Double

The Number to store in the JsonValue.

Returns

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

Creates the string for a JsonValue.

public : static JsonValue CreateStringValue(Platform::String input)
public static JsonValue CreateStringValue(String input)
Public Static Function CreateStringValue(input As String) As JsonValue
var jsonValue = Windows.Data.Json.JsonValue.createStringValue(input);
Parameters
input
Platform::String String String String

The string for the JsonValue.

Returns

GetArray() 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
var jsonArray = jsonValue.getArray();
Returns

GetBoolean() GetBoolean() GetBoolean() GetBoolean()

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

public : Platform::Boolean GetBoolean()
public bool GetBoolean()
Public Function GetBoolean() As bool
var bool = jsonValue.getBoolean();
Returns
Platform::Boolean bool bool bool

The Boolean value.

GetNumber() 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
var double = jsonValue.getNumber();
Returns
double double double double

The number value.

GetObject() 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
var jsonObject = jsonValue.getObject();
Returns

GetString() GetString() GetString() GetString()

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

public : Platform::String GetString()
public string GetString()
Public Function GetString() As string
var string = jsonValue.getString();
Returns
Platform::String string string string

The String value.

Parse(String) 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(Platform::String input)
public static JsonValue Parse(String input)
Public Static Function Parse(input As String) As JsonValue
var jsonValue = Windows.Data.Json.JsonValue.parse(input);
Parameters
input
Platform::String String String String

The specified JSON string.

Returns

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

See Also

Stringify() Stringify() Stringify() Stringify()

Retrieves the JSON representation of the encapsulated value.

public : Platform::String Stringify()
public string Stringify()
Public Function Stringify() As string
var string = jsonValue.stringify();
Returns
Platform::String string string string

A JSON representation of the encapsulated value.

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() ToString()

Retrieves the JSON representation of the encapsulated value.

public : Platform::String ToString()
public string ToString()
Public Function ToString() As string
var string = jsonValue.toString();
Returns
Platform::String string string string

A JSON representation of the encapsulated value.

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) TryParse(String, JsonValue)

Parses the specified string into a JsonValue.

public : static Platform::Boolean TryParse(Platform::String input, JsonValue result)
public static bool TryParse(String input, JsonValue result)
Public Static Function TryParse(input As String, result As JsonValue) As bool
var bool = Windows.Data.Json.JsonValue.tryParse(input, result);
Parameters
input
Platform::String String String String

The specified string.

Returns
Platform::Boolean bool bool bool

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

See Also