主要内容

mps.json.decoderesponse

将服务器响应中的 JSON 文本转换为 MATLAB 数据

说明

lhs = mps.json.decoderesponse(response) 用于读取成功的 MATLAB® 函数调用返回的输出参量的 JSON 有效负载。

示例

error = mps.json.decoderesponse(response) 用于读取失败的 MATLAB 函数调用抛出的 MATLAB 错误的 JSON 有效负载。

示例

全部折叠

mps.json.decoderesponse('{"lhs":[[[1, 2, 3, 4]]]}')
ans =
  1x1 cell array
    {1x4 double}

执行 mps.json.encoderequestmps.json.decoderesponse,以使用 webwrite 调用在 MATLAB Production Server™ 上部署的函数。在本例中,学生姓名及他们对应的分数被部署到 MATLAB Production Serversortstudents 函数中,该函数根据学生的分数对他们进行排序。返回的结果相当于从 MATLAB 调用函数 sortstudents(struct('name', 'Ed', 'score', 83), struct('name', 'Toni', 'score', 91)) 得到的数据。

假设有一个可部署存档 studentapp,该存档中包含部署到服务器的 MATLAB 函数 sortstudents

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 函数调用的 JSON 结果,指定为 JSON 文本。

输出参量

全部折叠

来自从 MATLAB Production Server 调用的 MATLAB 函数的输出参量的元胞向量。

当从 MATLAB Production Server 调用的 MATLAB 函数请求导致 MATLAB 错误时生成的输出,以 struct 数组形式返回。

版本历史记录

在 R2018a 中推出