Main Content

このページの翻訳は最新ではありません。ここをクリックして、英語の最新版を参照してください。

mps.json.encoderequest

MATLAB Production Server JSON スキーマを使用してサーバー要求の MATLAB データを JSON テキストに変換する

説明

text = mps.json.encoderequest(rhs) は、MATLAB® Production Server™ の JSON スキーマを使用して、デプロイされた MATLAB 関数への入力である要求をエンコードします。MATLAB Production Server への呼び出しを行うために必要な、'Nargout''OutputFormat' などの MATLAB 変数およびオプションが含まれたサーバー要求をビルドします。

text = mps.json.encoderequest(rhs,Name,Value) は、特定の入力ケースに対して、名前と値のペアの引数を 1 つ以上使用して追加オプションを指定します。

すべて折りたたむ

mps.json.encoderequest({[1 2 3 4]})
ans =
    '{"rhs":[[[1,2,3,4]]],"nargout":1,"outputFormat":{"mode":"small","nanType":"string"}}'
rhs = {['Red'], [15], [1 3; 5 7], ['Green']};
mps.json.encoderequest(rhs, 'Nargout', 3, 'OutputFormat', 'large')
ans =
    '{"rhs":["Red",15,[[1,3],[5,7]],"Green"],"nargout":3,"outputFormat":{"mode":"large","nanType":"string"}}'

2 つの行列を水平方向に連結する MATLAB 関数 horzcat を使用します。

a = [1 2; 5 6];
b = [3 4; 7 8];
mps.json.encoderequest({horzcat(a,b)})
ans =
    '{"rhs":[[[1,2,3,4],[5,6,7,8]]],"nargout":1,"outputFormat":{"mode":"small","nanType":"string"}}'

mps.json.encoderequestmps.json.decoderesponse を実行し、webwrite を使用して MATLAB Production Server にデプロイされた関数を呼び出します。この場合、学生の名前と対応するスコアは、MATLAB Production Server にデプロイされたスコアに基づいて学生を並べ替える関数 sortstudents に渡されます。返される結果は、MATLAB から関数 sortstudents(struct('name', 'Ed', 'score', 83), struct('name', 'Toni', 'score', 91)) を呼び出す場合と同等になります。

サーバーへデプロイされた MATLAB 関数 sortstudents を含むデプロイ可能なアーカイブ studentapp があると仮定します。

data = {struct('name', 'Ed', 'score', 83), struct('name', 'Toni', 'score', 91)};
body = mps.json.encoderequest(data);

options = weboptions;

% Create a weboptions object that instructs webread to return JSON text
options.ContentType = 'text';

% Create a weboptions object that instructs webwrite to encode character vector data as JSON to post it to a web service
options.MediaType = 'application/json';    

response = webwrite('http://localhost:9910/studentapp/sortstudents', body, options);

result = mps.json.decoderesponse(response);

入力引数

すべて折りたたむ

MATLAB Production Server にデプロイされた、呼び出す MATLAB 関数の入力引数。cell ベクトルとして指定します。

名前と値の引数

オプションのペアの引数を Name1=Value1,...,NameN=ValueN として指定します。ここで、Name は引数名で、Value は対応する値です。名前と値の引数は他の引数の後に指定する必要がありますが、ペアの順序は考慮されません。

R2021a より前では、コンマを使用してそれぞれの名前と値を区切り、Name を引用符で囲みます。

例: mps.json.encoderequest(rhs, 'Format', 'large')

MATLAB Production Server にデプロイされた関数の出力引数の数。'Nargout' と出力引数の数で構成されたコンマ区切りのペアとして指定します。

mps.json.encoderequest(rhs, 'Nargout', 3).

rhs をエンコードする形式。'Format' と形式 'small' または 'large' で構成されるコンマ区切りのペアとして指定します。

small 形式は JSON での MATLAB データ型のより単純な表現ですが、large 形式はより一般的な表現です。詳細については、MATLAB データ型の JSON 表現を参照してください。

rhsNaNInf-Inf をエンコードする形式。'NaNInfType' と JSON データ型 'string' および 'object' で構成されたコンマ区切りのペアとして指定します。

MATLAB Production Server にデプロイされた MATLAB 関数からの応答の形式。'OutputFormat' と形式 'small' または 'large' で構成されるコンマ区切りのペアとして指定します。

出力形式は mps.json.encoderequest(rhs, 'OutputFormat', 'large') を使用して設定されます。

NaNInf-Inf が含まれている、MATLAB Production Server にデプロイされた MATLAB 関数からの応答のタイプ。'OutputNaNInfType' と JSON データ型 'string' および 'object' で構成されたコンマ区切りのペアとして指定します。

出力応答の NaN タイプは mps.json.encoderequest(rhs, 'OutputNaNInfType', 'object') を使用して設定されます。

可読性を高めるための text の書式設定。'PrettyPrint' と、logical 'true' または 'false' で構成されるコンマ区切りのペアとして指定します。構文は mps.json.encoderequest(rhs,'PrettyPrint',true) です。

出力引数

すべて折りたたむ

MATLAB Production Server の JSON スキーマの JSON 形式のテキスト。文字ベクトルとして返されます。

バージョン履歴

R2018a で導入