WwwFormUrlDecoder class

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

Syntax


var wwwFormUrlDecoder = new Windows.Foundation.WwwFormUrlDecoder();

Attributes

[DualApiPartition()]
[MarshalingBehavior(Agile)]
[Threading(Both)]
[Version(0x06020000)]

Members

The WwwFormUrlDecoder class has these types of members:

Constructors

The WwwFormUrlDecoder class has these constructors.

ConstructorDescription
WwwFormUrlDecoder Creates and initializes a new instance of the WwwFormUrlDecoder class.

 

Methods

The WwwFormUrlDecoder class has these methods. With C#, Visual Basic, and C++, it also inherits methods from the Object class.

MethodDescription
First [C++, JavaScript]Gets an iterator that represents the first name-value pair in the current URL query string.
GetAt [C++, JavaScript]Gets the name-value pair at the specified index in the current URL query string.
GetFirstValueByName Gets the first name-value pair that has the specified name, as obtained from the constructing Uniform Resource Identifier (URI) query string.
GetMany [C++, JavaScript]Gets name-value pairs starting at the specified index in the current URL query string.
IndexOf [C++, JavaScript]Gets a value indicating whether the specified IWwwFormUrlDecoderEntry is at the specified index in the current URL query string.

 

Properties

The WwwFormUrlDecoder class has these properties.

PropertyAccess typeDescription

Count [C#, VB]

Read-onlyGets the number of elements contained in the collection.

Item [C#, VB]

Read-onlyGets or sets the element at the specified index.

Size [C++, JavaScript]

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

 

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 or Item 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 Item, IndexOf and so on). 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 apps. 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.

Requirements (device family)

Device family

Universal

API contract

Windows.Foundation.UniversalApiContract, introduced version 1.0

Namespace

Windows.Foundation
Windows::Foundation [C++]

Metadata

Windows.Foundation.UniversalApiContract.winmd

Requirements (operating system)

Minimum supported client

Windows 8 [Windows Store apps, desktop apps]

Minimum supported server

Windows Server 2012 [Windows Store apps, desktop apps]

Minimum supported phone

Windows Phone 8

Namespace

Windows.Foundation
Windows::Foundation [C++]

Metadata

Windows.winmd

See also

Object
IIterable(IWwwFormUrlDecoderEntry)
IVectorView(IWwwFormUrlDecoderEntry)
IWwwFormUrlDecoderEntry
Uri.QueryParsed

 

 

Show:
© 2015 Microsoft