Main Content

mps.json.decoderesponse

Convert JSON text from a server response to MATLAB data

Description

lhs = mps.json.decoderesponse(response) reads the JSON payload of the output arguments returned from a successful MATLAB® function call.

example

error = mps.json.decoderesponse(response) reads the JSON payload of the MATLAB error thrown from a failed MATLAB function call.

Examples

collapse all

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

Execute mps.json.encoderequest and mps.json.decoderesponse to call a function deployed on MATLAB Production Server™ using webwrite. In this case, student names and their corresponding scores are deployed to MATLAB Production Server to the sortstudents function that sorts students based on their scores. The result returned is the equivalent to calling the function sortstudents(struct('name', 'Ed', 'score', 83), struct('name', 'Toni', 'score', 91)) from MATLAB.

Assume that there is a deployable archive studentapp that contains a MATLAB function sortstudents deployed to the server.

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);

Input Arguments

collapse all

JSON result from a MATLAB function call specified as JSON text.

Output Arguments

collapse all

Cell vector of output arguments that are from a MATLAB function called from MATLAB Production Server.

Generated output when request to MATLAB function called from MATLAB Production Server results in a MATLAB error returned as a struct array.

Version History

Introduced in R2018a