Main Content

matlab.net.QueryParameter class

Package: matlab.net

Parameter in query portion of uniform resource identifier (URI)

Description

Use the QueryParameter class to create a URI query string of the form:

name1=value1&name2=value2&name3=value3

where each name=value segment is a QueryParameter object, converted to a string using the string method. The string method on a vector of QueryParameter objects joins the results using the & character. The string method converts any values to strings and performs all necessary encoding of special characters in the result.

Class Attributes

Sealed
true

For information on class attributes, see Class Attributes.

Creation

Description

obj = matlab.net.QueryParameter creates an empty query parameter.

obj = matlab.net.QueryParameter(paramName,paramValue) creates a query parameter vector of paramName,paramValue pair arguments. You can specify several argument pairs in any order as paramName1,paramValue1,...,paramNameN,paramValueN.

example

obj = matlab.net.QueryParameter(qStruct) creates a query parameter vector from a structure.

example

obj = matlab.net.QueryParameter(queryStr) parses queryStr into the query.

obj = matlab.net.QueryParameter(___,Format) specifies the format to be used for nonscalar values, and can include any of the input arguments in previous syntaxes.

Input Arguments

expand all

Parameter name, specified as a string or a character vector.

Parameter value, specified as a type required by paramName.

Parameter names and values, specified as a structure. The fields of qStruct define the parameter names and values.

Data Types: struct

Parameter names and values, specified as a string or a character vector. The queryStr is a completed, encoded query as it would appear in a URI, with an optional leading ? character.

queryStr is split at the & characters into individual name=value query parameters. The Name property is set to name and the Value property is set to value.

A triplet of characters of the form % and two hex digits represents a percent-encoded byte. A sequence of these bytes is treated as UTF-8 encoded characters, which are decoded to form the Name and Value properties of the QueryParameters. Also, any plus sign '+' in queryStr is treated as a space '%20'. When the QueryParameter is converted back to a string, any required percent-encoding is performed only on characters that should be encoded. This action is done whether or not those characters were originally encoded in queryStr, so the result from the string method might not exactly match queryStr. The meaning, however, is the same when used in a URI.

For example, the UTF-8 encoding for the euro sign is E2 82 AC.

q1 = matlab.net.QueryParameter('V=%e2%82%ac')
q1 = 

  QueryParameter with properties:

      Name: "V"
     Value: "€"
    Format: csv

The + and %20 characters are treated as spaces.

q2 = matlab.net.QueryParameter('V=a+b%20c')
q2 = 

  QueryParameter with properties:

      Name: "V"
     Value: "a b c"
    Format: csv

The string method implements percent-encoding on characters that require encoding. For example, the is encoded.

string(q1)
ans = V=%E2%82%AC

However, the characters in the queryStr argument 'V=a+b%20c' do not need encoding.

q3 = string(q2)
q3 = V=a+b+c

Although the result from the string method does not match queryStr, the values are identical when used in a URI.

Properties

expand all

Parameter name, specified as a string or a character vector.

Parameter value, specified as a real number, logical, datetime (with value other than NaT), string, character vector, or a vector or cell vector of these values. If Value is any other type, then Value must support string or char methods that convert the value to a character vector. If empty, Value is treated as an empty string.

Encoding format, specified as a matlab.net.ArrayFormat enumeration, to use for encoding Value if it is a vector.

Methods

expand all

Examples

collapse all

Create a structure field name this and set it to the value that.

qStruct.this = 'that';
QP = matlab.net.QueryParameter(qStruct)
QP = 
  QueryParameter with properties:

      Name: "this"
     Value: 'that'
    Format: csv

Create a character vector with two queries, this=that and one=2. The QueryParameter method splits qStr at the & character into two QueryParameter objects.

qStr = '?this=that&one=2';
QPs = matlab.net.QueryParameter(qStr);

The name=value pairs in qStr define the Name and Value properties.

name1 = QPs(1).Name
name1 = 
"this"
value1 = QPs(1).Value
value1 = 
"that"
name2 = QPs(2).Name
name2 = 
"one"
value2 = QPs(2).Value
value2 = 
"2"

Version History

Introduced in R2016b