JsonObject
JsonObject
JsonObject
JsonObject
Class
Definition
Represents a JSON object containing a collection of name and JsonValue pairs.
JsonObject is an activatable class that implements JsonValue and the IMap(String, IJsonValue) interface such that its name/value pairs can be manipulated like a dictionary. When there are values with duplicated names, the last name/value pair will be stored.
public : sealed class JsonObject : IJsonObject, IJsonObjectWithDefaultValues, IJsonValue, IIterable, IMap, IStringablepublic sealed class JsonObject : IJsonObject, IJsonObjectWithDefaultValues, IJsonValue, IEnumerable, IDictionary, IStringablePublic NotInheritable Class JsonObject Implements IJsonObject, IJsonObjectWithDefaultValues, IJsonValue, IEnumerable, IDictionary, 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
For an example of how these class methods are used to parse an object from a JSON string and convert it into a JsonObject object, update the name/value pairs the object contains, and then serialize the updated JsonObject object as a JSON string, see Using JavaScript Object Notation (JSON).
Constructors
JsonObject() JsonObject() JsonObject() JsonObject()
Initializes a new instance of a JsonObject that represents a JSON object containing a collection of name and JsonValue pairs.
public : JsonObject()public JsonObject()Public Sub New()// This API is not available in Javascript.
Properties
Item[TKey] Item[TKey] Item[TKey] Item[TKey]
Gets or sets the element with the specified key.
This member is not implemented in C++TValue this[TKey key] { get; set; }Property Item(key As TKey) As TValueTValue this[TKey key] { get; set; }
- key
- TKey TKey TKey TKey
The key of the element to get or set.
- Value
- TValue TValue TValue TValue
The element with the specified key.
key is null.
The property is retrieved and key is not found.
The property is set and the System.Collections.Generic.IDictionary`2 is read-only.
Keys Keys Keys Keys
Gets an System.Collections.Generic.ICollection`1 containing the keys of the System.Collections.Generic.IDictionary`2.
This member is not implemented in C++ICollection<TKey> Keys { get; }ReadOnly Property Keys As ICollection(Of TKey)ICollection<TKey> Keys { get; }
- Value
An System.Collections.Generic.ICollection`1 containing the keys of the object that implements System.Collections.Generic.IDictionary`2.
Size Size Size Size
Gets the size (count) of the collection.
public : unsigned int Size { get; }This member is not implemented in C#This member is not implemented in VB.Net// This API is not available in Javascript.
- Value
- unsigned int uint uint uint
The count of items in the collection.
Values Values Values Values
Gets an System.Collections.Generic.ICollection`1 containing the values in the System.Collections.Generic.IDictionary`2.
This member is not implemented in C++ICollection<TValue> Values { get; }ReadOnly Property Values As ICollection(Of TValue)ICollection<TValue> Values { get; }
- Value
An System.Collections.Generic.ICollection`1 containing the values in the object that implements System.Collections.Generic.IDictionary`2.
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
Add(TKey, TValue) Add(TKey, TValue) Add(TKey, TValue) Add(TKey, TValue)
Adds an element with the provided key and value to the System.Collections.Generic.IDictionary`2.
This member is not implemented in C++void Add(TKey key, TValue value)Sub Add(key As TKey, value As TValue)void Add(TKey key, TValue value)
- key
- TKey TKey TKey TKey
The object to use as the key of the element to add.
- value
- TValue TValue TValue TValue
The object to use as the value of the element to add.
key is null.
An element with the same key already exists in the System.Collections.Generic.IDictionary`2.
The System.Collections.Generic.IDictionary`2 is read-only.
Clear() Clear() Clear() Clear()
Removes all items from the collection.
public : void Clear()This member is not implemented in C#This member is not implemented in VB.Net// This API is not available in Javascript.
ContainsKey(TKey) ContainsKey(TKey) ContainsKey(TKey) ContainsKey(TKey)
Determines whether the System.Collections.Generic.IDictionary`2 contains an element with the specified key.
This member is not implemented in C++bool ContainsKey(TKey key)Function ContainsKey(key As TKey) As Booleanbool ContainsKey(TKey key)
- key
- TKey TKey TKey TKey
The key to locate in the System.Collections.Generic.IDictionary`2.
true if the System.Collections.Generic.IDictionary`2 contains an element with the key; otherwise, false.
key is null.
First() First() First() First()
Returns the iterator for iteration over the key/value pairs in the JsonObject.
public : IIterator<IKeyValuePair<PlatForm::String, IJsonValue>> First()This member is not implemented in C#This member is not implemented in VB.Net// This API is not available in Javascript.
The iterator object. The iterator's current position is at the 0-index position, or at the array end if the array is empty.
GetEnumerator() GetEnumerator() GetEnumerator() GetEnumerator()
Returns an enumerator that iterates through the collection.
This member is not implemented in C++IEnumerator<T> GetEnumerator()Function GetEnumerator As IEnumerator(Of T)IEnumerator<T> GetEnumerator()
An enumerator that can be used to iterate through the collection.
GetNamedArray(String) GetNamedArray(String) GetNamedArray(String) GetNamedArray(String)
Gets the JsonArray value with the specified name.
public : JsonArray GetNamedArray(PlatForm::String name)public JsonArray GetNamedArray(String name)Public Function GetNamedArray(name As String) As JsonArray// This API is not available in Javascript.
- name
- PlatForm::String String String String
The name.
Remarks
This method should always used with a try/catch block because it throws an exception if the name found is not a JsonArray type or the name is not found.
- See Also
GetNamedArray(String, JsonArray) GetNamedArray(String, JsonArray) GetNamedArray(String, JsonArray) GetNamedArray(String, JsonArray)
Gets the JsonArray value with the specified name, or the provided default value if no such named value is found.
public : JsonArray GetNamedArray(PlatForm::String name, JsonArray defaultValue)public JsonArray GetNamedArray(String name, JsonArray defaultValue)Public Function GetNamedArray(name As String, defaultValue As JsonArray) As JsonArray// This API is not available in Javascript.
- name
- PlatForm::String String String String
The name.
The default value to use if the JSON property is not found.
The JsonArray with the specified name, or if this value wasn't found, the defaultValue is returned.
- See Also
GetNamedBoolean(String) GetNamedBoolean(String) GetNamedBoolean(String) GetNamedBoolean(String)
Gets the Boolean value with the specified name.
public : PlatForm::Boolean GetNamedBoolean(PlatForm::String name)public bool GetNamedBoolean(String name)Public Function GetNamedBoolean(name As String) As bool// This API is not available in Javascript.
- name
- PlatForm::String String String String
The name.
The Boolean with the specified name.
Remarks
This method should always used with a try/catch block because it throws an exception if the name found is not a Boolean type or the name is not found.
- See Also
GetNamedBoolean(String, Boolean) GetNamedBoolean(String, Boolean) GetNamedBoolean(String, Boolean) GetNamedBoolean(String, Boolean)
Gets the Boolean value with the specified name, or the provided default value if no such named value is found.
public : PlatForm::Boolean GetNamedBoolean(PlatForm::String name, bool defaultValue)public bool GetNamedBoolean(String name, Boolean defaultValue)Public Function GetNamedBoolean(name As String, defaultValue As Boolean) As bool// This API is not available in Javascript.
- name
- PlatForm::String String String String
The name.
- defaultValue
- bool Boolean Boolean Boolean
The default value to use if the JSON property is not found.
The Boolean with the specified name, or if this value wasn't found, the defaultValue is returned.
- See Also
GetNamedNumber(String) GetNamedNumber(String) GetNamedNumber(String) GetNamedNumber(String)
Gets the number value (a Double) with the specified name.
public : double GetNamedNumber(PlatForm::String name)public double GetNamedNumber(String name)Public Function GetNamedNumber(name As String) As double// This API is not available in Javascript.
- name
- PlatForm::String String String String
The name.
The Double with the specified name.
Remarks
This method should always used with a try/catch block because it throws an exception if the name found is not a Double type or the name is not found.
- See Also
GetNamedNumber(String, Double) GetNamedNumber(String, Double) GetNamedNumber(String, Double) GetNamedNumber(String, Double)
Gets the number value (a Double) with the specified name, or the provided default value if no such named value is found.
public : double GetNamedNumber(PlatForm::String name, double defaultValue)public double GetNamedNumber(String name, Double defaultValue)Public Function GetNamedNumber(name As String, defaultValue As Double) As double// This API is not available in Javascript.
- name
- PlatForm::String String String String
The name.
- defaultValue
- double Double Double Double
The default value to use if the JSON property is not found.
The Double with the specified name, or if this value wasn't found, the defaultValue is returned.
- See Also
GetNamedObject(String) GetNamedObject(String) GetNamedObject(String) GetNamedObject(String)
Gets the JsonObject value with the specified name.
public : JsonObject GetNamedObject(PlatForm::String name)public JsonObject GetNamedObject(String name)Public Function GetNamedObject(name As String) As JsonObject// This API is not available in Javascript.
- name
- PlatForm::String String String String
The name.
The JsonObject value with the specified name.
Remarks
This method should always used with a try/catch block because it throws an exception if the name found is not a JsonObject type or the name is not found.
- See Also
GetNamedObject(String, JsonObject) GetNamedObject(String, JsonObject) GetNamedObject(String, JsonObject) GetNamedObject(String, JsonObject)
Gets the JsonObject value with the specified name, or the provided default value if no such named value is found.
public : JsonObject GetNamedObject(PlatForm::String name, JsonObject defaultValue)public JsonObject GetNamedObject(String name, JsonObject defaultValue)Public Function GetNamedObject(name As String, defaultValue As JsonObject) As JsonObject// This API is not available in Javascript.
- name
- PlatForm::String String String String
The name.
- defaultValue
- JsonObject JsonObject JsonObject JsonObject
The default value to use if the JSON property is not found.
The JsonObject with the specified name, or if this value wasn't found, the defaultValue is returned.
- See Also
GetNamedString(String) GetNamedString(String) GetNamedString(String) GetNamedString(String)
Gets the String value with the specified name.
public : PlatForm::String GetNamedString(PlatForm::String name)public string GetNamedString(String name)Public Function GetNamedString(name As String) As string// This API is not available in Javascript.
- name
- PlatForm::String String String String
The name.
The String value with the specified name.
Remarks
This method should always used with a try/catch block because it throws an exception if the name found is not a String type or the name is not found.
- See Also
GetNamedString(String, String) GetNamedString(String, String) GetNamedString(String, String) GetNamedString(String, String)
Gets the String value with the specified name, or the provided default value if no such named value is found.
public : PlatForm::String GetNamedString(PlatForm::String name, PlatForm::String defaultValue)public string GetNamedString(String name, String defaultValue)Public Function GetNamedString(name As String, defaultValue As String) As string// This API is not available in Javascript.
- name
- PlatForm::String String String String
The name.
- defaultValue
- PlatForm::String String String String
The default value to use if the JSON property is not found.
The String with the specified name, or if this value wasn't found, the defaultValue is returned.
- See Also
GetNamedValue(String) GetNamedValue(String) GetNamedValue(String) GetNamedValue(String)
Gets the JsonValue value with the specified name.
public : JsonValue GetNamedValue(PlatForm::String name)public JsonValue GetNamedValue(String name)Public Function GetNamedValue(name As String) As JsonValue// This API is not available in Javascript.
- name
- PlatForm::String String String String
The name.
Remarks
This method should always used with a try/catch block because it throws an exception if the name found is not a JsonValue type or the name is not found.
- See Also
GetNamedValue(String, JsonValue) GetNamedValue(String, JsonValue) GetNamedValue(String, JsonValue) GetNamedValue(String, JsonValue)
Gets the specified JsonValue value, or the provided default value if no such named value is found.
public : JsonValue GetNamedValue(PlatForm::String name, JsonValue defaultValue)public JsonValue GetNamedValue(String name, JsonValue defaultValue)Public Function GetNamedValue(name As String, defaultValue As JsonValue) As JsonValue// This API is not available in Javascript.
- name
- PlatForm::String String String String
The name.
The default value to use if the JSON property is not found.
The JsonValue with the specified name, or if this value wasn't found, the defaultValue is returned.
- See Also
GetObject() GetObject() GetObject() GetObject()
Gets the 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.
The encapsulated JsonObject.
GetView() GetView() GetView() GetView()
Gets a JsonObject view.
public : IMapView<PlatForm::String, IJsonValue> GetView()This member is not implemented in C#This member is not implemented in VB.Net// This API is not available in Javascript.
The JsonObject view.
HasKey(String) HasKey(String) HasKey(String) HasKey(String)
Indicates whether the JsonObject has an entry with the requested key.
public : PlatForm::Boolean HasKey(PlatForm::String key)This member is not implemented in C#This member is not implemented in VB.Net// This API is not available in Javascript.
- key
- PlatForm::String String String String
The requested key.
true if the JsonObject has an entry with the requested key; otherwise, false.
Insert(String, IJsonValue) Insert(String, IJsonValue) Insert(String, IJsonValue) Insert(String, IJsonValue)
Adds a new entry to the JsonObject.
public : PlatForm::Boolean Insert(PlatForm::String key, IJsonValue value)This member is not implemented in C#This member is not implemented in VB.Net// This API is not available in Javascript.
- key
- PlatForm::String String String String
The key to insert.
The IJsonValue to insert.
true if calling the method replaced a value that already existed for the key; false if calling the method defined a new key.
Lookup(String) Lookup(String) Lookup(String) Lookup(String)
Gets the JSON value associated with the supplied key, if an entry with that key exists.
public : IJsonValue Lookup(PlatForm::String key)This member is not implemented in C#This member is not implemented in VB.Net// This API is not available in Javascript.
- key
- PlatForm::String String String String
The requested key.
The value, if an item with the specified key exists. Use the HasKey method to determine whether the key exists.
Parse(String) Parse(String) Parse(String) Parse(String)
Parses the specified JSON string that represents a JsonObject into a JSON value.
Note
This 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 JsonObject.
public : static JsonObject Parse(PlatForm::String input)public static JsonObject Parse(String input)Public Static Function Parse(input As String) As JsonObject// 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
Remove(TKey) Remove(TKey) Remove(TKey) Remove(TKey)
Removes the element with the specified key from the System.Collections.Generic.IDictionary`2.
This member is not implemented in C++bool Remove(TKey key)Function Remove(key As TKey) As Booleanbool Remove(TKey key)
- key
- TKey TKey TKey TKey
The key of the element to remove.
true if the element is successfully removed; otherwise, false. This method also returns false if key was not found in the original System.Collections.Generic.IDictionary`2.
key is null.
The System.Collections.Generic.IDictionary`2 is read-only.
Remove(String) Remove(String) Remove(String) Remove(String)
Removes a specific item from the JsonObject.
public : void Remove(PlatForm::String key)This member is not implemented in C#This member is not implemented in VB.Net// This API is not available in Javascript.
- key
- PlatForm::String String String String
The key of the item to remove.
SetNamedValue(String, IJsonValue) SetNamedValue(String, IJsonValue) SetNamedValue(String, IJsonValue) SetNamedValue(String, IJsonValue)
Sets the value of the first JsonValue object with the specified name to the specified value. If no such object is found, a new name and JsonValue pair is inserted into the JSON object.
public : void SetNamedValue(PlatForm::String name, IJsonValue value)public void SetNamedValue(String name, IJsonValue value)Public Function SetNamedValue(name As String, value As IJsonValue) As void// This API is not available in Javascript.
- name
- PlatForm::String String String String
The specified name.
The specified value.
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.
TryGetValue(TKey, out TValue) TryGetValue(TKey, out TValue) TryGetValue(TKey, out TValue) TryGetValue(TKey, out TValue)
Gets the value associated with the specified key.
This member is not implemented in C++bool TryGetValue(TKey key, out TValue value)Function TryGetValue(key As TKey, ByRef value As TValue) As Booleanbool TryGetValue(TKey key, out TValue value)
- key
- TKey TKey TKey TKey
The key whose value to get.
- value
- TValue TValue TValue TValue
When this method returns, the value associated with the specified key, if the key is found; otherwise, the default value for the type of the value parameter. This parameter is passed uninitialized.
true if the object that implements System.Collections.Generic.IDictionary`2 contains an element with the specified key; otherwise, false.
key is null.
TryParse(String, JsonObject) TryParse(String, JsonObject) TryParse(String, JsonObject) TryParse(String, JsonObject)
Parses the specified string that represents a JSON object into a JsonObject.
public : static PlatForm::Boolean TryParse(PlatForm::String input, JsonObject result)public static bool TryParse(String input, JsonObject result)Public Static Function TryParse(input As String, result As JsonObject) As bool// This API is not available in Javascript.
- input
- PlatForm::String String String String
The specified JSON string.
- result
- JsonObject JsonObject JsonObject JsonObject
The resultant JsonObject.
True if the JsonValue object was successfully created; otherwise, false.