JsonValue JsonValue JsonValue Class

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.

Syntax

Declaration

public sealed class JsonValuepublic sealed class JsonValuePublic NotInheritable Class JsonValue

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 summary

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

Methods summary

Creates a JsonValue from a Boolean.

Creates a JsonValue with a NULL value.

Creates a JsonValue from a Number (Double).

Creates the string for a JsonValue.

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

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

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

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

Gets a String if the ValueType of the encapsulated value is 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 TryParse(String, JsonObject) is a recommended alternative. A TryParse(String, JsonValue) call will return a boolean value to indicate success or failure and, if successful, the resultant JsonValue.

Retrieves the JSON representation of the encapsulated value.

Retrieves the JSON representation of the encapsulated value.

Parses the specified string into a JsonValue.

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 JsonValueTypepublic JsonValueType ValueType { get; }

    Property Value

Methods

  • CreateBooleanValue(Boolean)
    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 JsonValuepublic static JsonValue CreateBooleanValue(Boolean input)

    Parameters

    • input
      System.Boolean
      System.Boolean
      System.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 JsonValuepublic static 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 JsonValuepublic static JsonValue CreateNumberValue(Double input)

    Parameters

    • input
      System.Double
      System.Double
      System.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(String input)public static JsonValue CreateStringValue(String input)Public Static Function CreateStringValue(input As String) As JsonValuepublic static JsonValue CreateStringValue(String input)

    Parameters

    • input
      System.String
      System.String
      System.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 JsonArraypublic JsonArray GetArray()

    Returns

  • GetBoolean()
    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 boolpublic bool GetBoolean()

    Returns

    • 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 doublepublic double GetNumber()

    Returns

    • 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 JsonObjectpublic JsonObject GetObject()

    Returns

  • GetString()
    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 stringpublic string GetString()

    Returns

    • 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 TryParse(String, JsonObject) is a recommended alternative. A TryParse(String, JsonValue) 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 JsonValuepublic static JsonValue Parse(String input)

    Parameters

    • input
      System.String
      System.String
      System.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(String) 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, this method requires the specified input string to be a valid JSON object value. When implemented on the subclass @Windows.Data.Json.JsonArray.#ctor, 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.@Windows.Data.Json.JsonValue.Parse(System.String) or @Windows.Data.Json.JsonArray.#ctor.@Windows.Data.Json.JsonValue.Parse(System.String) succeeds. If Parse(String) fails, the object state remains intact.

  • Stringify()
    Stringify()
    Stringify()
    Stringify()

    Retrieves the JSON representation of the encapsulated value.

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

    Returns

    • 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 string ToString()public string ToString()Public Function ToString() As stringpublic string ToString()

    Returns

    • 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 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 boolpublic static bool TryParse(String input, JsonValue result)

    Parameters

    Returns

    • bool
      bool
      bool

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

Device family

Windows 10 (introduced v10.0.10240.0)

API contract

Windows.Foundation.UniversalApiContract (introduced v1)

Attributes

Windows.Foundation.Metadata.ContractVersionAttribute
Windows.Foundation.Metadata.DualApiPartitionAttribute
Windows.Foundation.Metadata.MarshalingBehaviorAttribute
Windows.Foundation.Metadata.StaticAttribute
Windows.Foundation.Metadata.StaticAttribute
Windows.Foundation.Metadata.ThreadingAttribute
Windows.Foundation.Metadata.WebHostHiddenAttribute

Details

Assembly

Windows.Data.Json.dll