Documentation

matlab.net.QueryParameter class

Package:matlab.net

Parameter in query portion of uniform resource identifier (URI)

Description

Use theQueryParameterclass to create a URI query string of the form:

name1=value1&name2=value2&name3=value3

where eachname=valuesegment is aQueryParameterobject, converted to a string using thestringmethod. Thestringmethod on a vector ofQueryParameterobjects joins the results using the&character. Thestringmethod converts any values to strings and performs all necessary encoding of special characters in the result.

Construction

obj = matlab.net.QueryParametercreates an empty query parameter.

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

example

obj = matlab.net.QueryParameter(qStruct)创建一个查询参数向量的结构。

example

obj = matlab.net.QueryParameter(qStr)parsesqStrinto 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 byparamName.

Parameter names and values, specified as a structure. The fields ofqStructdefine the parameter names and values.

Data Types:struct

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

qStris split at the&characters into individualname=valuequery parameters. TheNameproperty is set tonameand theValueproperty is set tovalue.

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 () isE2 82 AC.

q1 = matlab.net.QueryParameter('V=%e2%82%ac')
q1 = QueryParameter with properties: Name: "V" Value: "€" Format: csv

The+and%20characters are treated as spaces.

q2 = matlab.net.QueryParameter('V=a+b%20c')
q2 = QueryParameter with properties: Name: "V" Value: "a b c" Format: csv

Thestringmethod implements percent-encoding on characters that require encoding. For example, theis encoded.

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

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

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

Although the result from thestringmethod does not matchqStr, 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. IfValueis any other type, thenValuemust supportstringorcharmethods that convert the value to a character vector. If empty,Valueis treated as an empty string.

Encoding format, specified as amatlab.net.ArrayFormat枚举,用于编码Valueif it is a vector.

Methods

char Encoded query parameter as character vector
string Encoded query parameter as string

Attributes

Sealed true

Examples

expand all

Create a structure field namethisand set it to the valuethat.

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=thatandone=2. TheQueryParametermethod splitsqStrat the&character into twoQueryParameterobjects.

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

Thename=valuepairs inqStrdefine theNameandValueproperties.

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?