Documentation

This is machine translation

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

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

mps.json.decoderesponse

Convert JSON text from a server response to MATLAB data

Syntax

lhs = mps.json.decoderesponse(response)
error = mps.json.decoderesponse(response)

Description

example

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

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.

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.

Introduced in R2018a