WwwFormUrlDecoder 類別

定義

剖析 URL 查詢字串,並將結果公開為唯讀向量, (清單) 查詢字串中的名稱/值組。

public ref class WwwFormUrlDecoder sealed : IIterable<IWwwFormUrlDecoderEntry ^>, IVectorView<IWwwFormUrlDecoderEntry ^>
/// [Windows.Foundation.Metadata.Activatable(Windows.Foundation.IWwwFormUrlDecoderRuntimeClassFactory, 65536, Windows.Foundation.UniversalApiContract)]
/// [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 WwwFormUrlDecoder final : IIterable<IWwwFormUrlDecoderEntry>, IVectorView<IWwwFormUrlDecoderEntry>
/// [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)]
/// [Windows.Foundation.Metadata.Activatable(Windows.Foundation.IWwwFormUrlDecoderRuntimeClassFactory, 65536, "Windows.Foundation.UniversalApiContract")]
class WwwFormUrlDecoder final : IIterable<IWwwFormUrlDecoderEntry>, IVectorView<IWwwFormUrlDecoderEntry>
[Windows.Foundation.Metadata.Activatable(typeof(Windows.Foundation.IWwwFormUrlDecoderRuntimeClassFactory), 65536, typeof(Windows.Foundation.UniversalApiContract))]
[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 WwwFormUrlDecoder : IEnumerable<IWwwFormUrlDecoderEntry>, IReadOnlyList<IWwwFormUrlDecoderEntry>
[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)]
[Windows.Foundation.Metadata.Activatable(typeof(Windows.Foundation.IWwwFormUrlDecoderRuntimeClassFactory), 65536, "Windows.Foundation.UniversalApiContract")]
public sealed class WwwFormUrlDecoder : IEnumerable<IWwwFormUrlDecoderEntry>, IReadOnlyList<IWwwFormUrlDecoderEntry>
function WwwFormUrlDecoder(query)
Public NotInheritable Class WwwFormUrlDecoder
Implements IEnumerable(Of IWwwFormUrlDecoderEntry), IReadOnlyList(Of IWwwFormUrlDecoderEntry)
繼承
Object Platform::Object IInspectable WwwFormUrlDecoder
屬性
實作

Windows 需求

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

備註

使用 WwwFormUrlDecoder 類別,根據 「&」 和 「=」 符號的數目和位置,將查詢字串剖析成名稱/值組。 每個名稱/值組都是以 IWwwFormUrlDecoderEntry 物件來表示,該物件具有 Name 屬性和 Value 屬性 (兩個字元串) 。

使用 GetFirstValueByName 尋找特定的具名查詢字串參數。 所有語言都可以使用此方法。 您通常會使用 GetFirstValueByName 而不是 GetAt ,因為查詢字串中的項目順序通常並不重要,而參數名稱則是查詢部分的重要標識碼。 或者,如果您不確定查詢字串中有哪些名稱存在,您可以列舉完整的 WwwFormUrlDecoder 集合。

Uri.QueryParsed 屬性會根據 Uri 實例傳回完整的 WwwFormUrlDecoder。 因此,如果您使用 Visual C++ 元件延伸模組 (C++/CX) 或 JavaScript 程式代碼,而且您已經有 Uri 實例,則不需要建構新的 WwwFormUrlDecoder 物件, Uri 實例就已經有一個。 如果您有代表 URL 的字串或其查詢字串元件來自其他來源,例如來自 Windows.Web.Http API,您可能會建構 WwwFormUrlDecoder。

注意

此集合是向量,而不是對應,以防原始順序對實作有任何意義,而且因為同名在查詢字串中出現兩次合法,而對應沒有重複索引鍵則不合法。

集合成員清單

針對 .NET 使用方式,WwwFormUrlDecoder 具有具有 IWwwFormUrlDecoderEntry 條件約束之泛型 IReadOnlyList 的投影 API。 成員清單中會指出每個語言可用的 API。

針對 JavaScript,WwwFormUrlDecoder 的成員會顯示在成員清單中。 此外,WwwFormUrlDecoder 也支援 length 屬性、 Array.prototype 的成員,以及使用索引來存取專案。

.NET 使用量

.NET 程式代碼無法使用 Windows.Foundation.Uri 類別, (改用 System.Uri) 。 但 .NET 程式代碼可以且應該使用 WwwFormUrlDecoder。 使用 WwwFormUrlDecoder 比 “&” 和 “=” 字元的字串分割更簡單且較不容易出錯。 這因為編碼而變得複雜。 若要使用 WwwFormUrlDecoder,請呼叫 WwwFormUrlDecoder 建構函式,並傳入來自 System.UriQuery 值。 這會初始化新的 WwwFormUrlDecoder 物件。 然後使用 GetFirstValueByName 尋找特定的具名查詢字串參數。 或者,如果您不知道查詢字串中的內容,請列舉集合,以判斷可用的查詢字串參數。

針對集合中項目的類型使用 IWwwFormUrlDecoderEntry 介面, (這是 IndexOf) 輸入專案的方式。 請勿使用 WwwFormUrlDecoderEntry 類別,不適用於 .NET 使用。

WwwFormUrlDecoder 也有具有 IWwwFormUrlDecoderEntry 條件約束之泛型 IReadOnlyList 的投影 API,但這些 API 並不常用。

注意

System.Web.HttpUtility.ParseQueryString不適用於 Windows 執行階段 應用程式的 .NET。 WwwFormUrlDecoder 是建議的取代專案。

列舉 C# 或 Microsoft Visual Basic 中的集合

WwwFormUrlDecoder 是可列舉的,因此您可以使用 C# 中的 foreach 之類的語言特定語法來列舉集合中的專案。 編譯程式會為您執行類型轉換,而且您不需要明確地轉換 。IEnumerable<IWwwFormUrlDecoderEntry> 如果您需要明確轉換,例如,如果您想要呼叫 GetEnumerator,請使用 IWwwFormUrlDecoderEntry 條件約束轉換成 IEnumerable<T>

建構函式

WwwFormUrlDecoder(String)

建立並初始化 WwwFormUrlDecoder 類別的新實例。

屬性

Size

取得目前 URL 查詢字串中名稱/值組的數目。

方法

First()

取得反覆運算器,表示目前URL查詢字串中的名字/值組。

GetAt(UInt32)

取得目前 URL 查詢字串中位於指定索引處的名稱/值組。

GetFirstValueByName(String)

取得具有指定名稱的第一個名稱/值組,如從建構統一資源標識碼 (URI) 查詢字串取得。

GetMany(UInt32, IWwwFormUrlDecoderEntry[])

取得從目前 URL 查詢字串中指定索引開始的名稱/值組。

IndexOf(IWwwFormUrlDecoderEntry, UInt32)

取得值,指出指定的 IWwwFormUrlDecoderEntry 是否位於目前 URL 查詢字串中的指定索引。

適用於

另請參閱