WwwFormUrlDecoder Class

Definition

Parses a URL query string, and exposes the results as a read-only vector (list) of name-value pairs from the query string.

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)
Inheritance
Object Platform::Object IInspectable WwwFormUrlDecoder
Attributes
Implements

Windows requirements

Device family
Windows 10 (introduced in 10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced in v1.0)

Remarks

Use the WwwFormUrlDecoder class to parse a query string into name-value pairs, based on the number and placement of "&" and "=" symbols. Each name-value pair is represented by an IWwwFormUrlDecoderEntry object, which has a Name property and a Value property (both strings).

Use GetFirstValueByName to find a specific named query string parameter. All languages can use this method. You'd typically use GetFirstValueByName rather than GetAt because the order of items in a query string usually isn't important, whereas the parameter name is the important identifier of the parts of a query. Or, if you're not sure what names exist in the query string, you might enumerate over the complete WwwFormUrlDecoder collection.

The Uri.QueryParsed property returns a complete WwwFormUrlDecoder based on a Uri instance. So if you're using Visual C++ component extensions (C++/CX) or JavaScript code, and you already have a Uri instance, you won't need to construct a new WwwFormUrlDecoder object, the Uri instance already has one. You might construct a WwwFormUrlDecoder if you have a string representing a URL or its query string component from other sources, such as from a Windows.Web.Http API.

Note

This collection is a vector rather than a map in case the original order has any meaning to an implementation, and also because it's legal for the same name to appear in the query string twice, whereas it's not legal for maps to have duplicate keys.

Collection member lists

For .NET usage, WwwFormUrlDecoder has the projected APIs of a generic IReadOnlyList with a IWwwFormUrlDecoderEntry constraint. The APIs that are available for each language are indicated in the member lists.

For JavaScript, WwwFormUrlDecoder has the members shown in the member lists. In addition, WwwFormUrlDecoder supports a length property, members of Array.prototype, and using an index to access items.

.NET usage

.NET code can't use the Windows.Foundation.Uri class (you use System.Uri instead). But .NET code can and should use WwwFormUrlDecoder. Using WwwFormUrlDecoder is simpler and less error-prone than string-splitting on "&" and "=" characters. That gets complicated because of encoding. To use WwwFormUrlDecoder, call the WwwFormUrlDecoder constructor, passing in the Query value from your System.Uri. This initializes a new WwwFormUrlDecoder object. Then use GetFirstValueByName to find a specific named query string parameter. Or, if you don't know what's going to be in the query string, enumerate over the collection to determine the query string parameters that are available.

Use the IWwwFormUrlDecoderEntry interface for the type of the items in the collection (this is how the items are typed by IndexOf). Don't use the WwwFormUrlDecoderEntry class, it isn't available for .NET usage.

WwwFormUrlDecoder also has the projected APIs of a generic IReadOnlyList with a IWwwFormUrlDecoderEntry constraint, but these APIs aren't commonly used.

Note

System.Web.HttpUtility.ParseQueryString isn't available for .NET for Windows Runtime app. WwwFormUrlDecoder is the recommended replacement for it.

Enumerating the collection in C# or Microsoft Visual Basic

WwwFormUrlDecoder is enumerable, so you can use language-specific syntax such as foreach in C# to enumerate the items in the collection. The compiler does the type-casting for you and you won't need to cast to IEnumerable<IWwwFormUrlDecoderEntry> explicitly. If you do need to cast explicitly, for example if you want to call GetEnumerator, cast to IEnumerable<T> with an IWwwFormUrlDecoderEntry constraint.

Constructors

WwwFormUrlDecoder(String)

Creates and initializes a new instance of the WwwFormUrlDecoder class.

Properties

Size

Gets the number of the name-value pairs in the current URL query string.

Methods

First()

Gets an iterator that represents the first name-value pair in the current URL query string.

GetAt(UInt32)

Gets the name-value pair at the specified index in the current URL query string.

GetFirstValueByName(String)

Gets the first name-value pair that has the specified name, as obtained from the constructing Uniform Resource Identifier (URI) query string.

GetMany(UInt32, IWwwFormUrlDecoderEntry[])

Gets name-value pairs starting at the specified index in the current URL query string.

IndexOf(IWwwFormUrlDecoderEntry, UInt32)

Gets a value indicating whether the specified IWwwFormUrlDecoderEntry is at the specified index in the current URL query string.

Applies to

See also