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, IStringablepublic sealed class JsonValue : IJsonValue, IStringablePublic NotInheritable Class JsonValue Implements IJsonValue, IStringable// This API is not available in Javascript.
- Attributes
| 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// This API is not available in Javascript.
The JSON value type.
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// This API is not available in Javascript.
- input
- bool Boolean Boolean Boolean
The value to store in the JsonValue.
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// This API is not available in Javascript.
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// This API is not available in Javascript.
- input
- double Double Double Double
The Number to store in the JsonValue.
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// This API is not available in Javascript.
- input
- PlatForm::String String String String
The string for the JsonValue.
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// This API is not available in Javascript.
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// This API is not available in Javascript.
- input
- PlatForm::String String String String
The specified JSON string.
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// This API is not available in Javascript.
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// This API is not available in Javascript.
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// This API is not available in Javascript.
- input
- PlatForm::String String String String
The specified string.
True if the JsonValue object was successfully created; otherwise, false.