Documentation

This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

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.

Construction

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(qStr) parses qStr 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 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 character vector. The qStr is a completed, encoded query as it would appear in a URI, with an optional leading ? character.

qStr 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. 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 qStr 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 qStr, the values are identical when used in a URI.

Properties

expand all

Parameter name, specified as a string or 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

charEncoded query parameter as character vector
stringEncoded query parameter as string

Attributes

Sealedtrue

Examples

expand 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"

Introduced in R2016b

Was this topic helpful?