JsonValue 類別

定義

實作代表 JSON 值的 IJsonValue 介面。

JsonValue 物件可以代表布林值、數位和字串的三種基本 JSON 實值型別,也可以藉由提供存取它們的方式來代表 Array 和 Object 的複雜實值型別。

public ref class JsonValue sealed : IJsonValue, IStringable
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
/// [Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
class JsonValue final : IJsonValue, IStringable
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
[Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
public sealed class JsonValue : IJsonValue, IStringable
Public NotInheritable Class JsonValue
Implements IJsonValue, IStringable
繼承
Object Platform::Object IInspectable JsonValue
屬性
實作

Windows 需求

裝置系列
Windows 10 (已於 10.0.10240.0 引進)
API contract
Windows.Foundation.UniversalApiContract (已於 v1.0 引進)

備註

JsonValue 物件具有多載建構函式,可從 JSON String、Number 或 Boolean 值具現化新的物件,以及具現化 ValueTypeNull之 JsonValue 物件的預設建構函式。

如需如何使用這些類別方法剖析 JSON 字串中的數位或字串,並將其轉換成 JsonValue 物件,請參閱 使用 JavaScript 物件標記法 (JSON)

屬性

ValueType

取得封裝 JSON 值的型別。 可能的型別是由 JsonValueType所定義。

方法

CreateBooleanValue(Boolean)

從布林值建立 JsonValue

CreateNullValue()

使用Null值建立JsonValue

CreateNumberValue(Double)

從數位 (Double) 建立JsonValue

CreateStringValue(String)

建立 JsonValue的字串。

GetArray()

如果封裝值的 ValueType 為 Array,則取得 陣列

GetBoolean()

如果封裝值的ValueType為布林值,則取得布林值

GetNumber()

如果封裝值的ValueType為 (Number,則取得Double) 數位

GetObject()

如果封裝值的ValueTypeObject,則取得JsonObject

GetString()

如果封裝值的ValueTypeString,則取得String

Parse(String)

將指定的 JSON 字串剖析為 JsonValue

注意

如果提供的 JSON 字串無效,這個方法會擲回例外狀況。 建議使用 JsonObject.TryParseTryParse呼叫會傳回布林值,以指出成功或失敗,如果成功,則為產生的JsonValue

Stringify()

擷取封裝值的 JSON 表示。

ToString()

擷取封裝值的 JSON 表示。

TryParse(String, JsonValue)

將指定的字串剖析為 JsonValue

適用於

另請參閱