restReqBodyGetJSON (Function)

Top  Previous  Next

Architecture:

NX32L

Device support:

ALL

Firmware version:

2.10.00


This function will read the contents of the body of the request as a JSON structure.

 

Input:

req : SYSHANDLE

A handle to the request.

 

 

Output:

json : SYSHANDLE

A handle to the JSON structure created from the body content.

When the JSON structure is no longer needed, it must be released using jsonFree.

 

 

 

Returns: INT

1


- Success

0


- Not supported

-1


- Invalid request

-2


- The max number of JSON structures have already been created.

-3


- Failed to create JSON structure. Body content might not be valid JSON.

 

Declaration:

FUNCTION restReqBodyGetJSON : INT;
VAR_INPUT
  req             : SYSHANDLE;
  json            : ACCESS SYSHANDLE;
END_VAR;

 

 

Example:

 
FUNCTION CALLBACK devicesGetCallback: INT;
VAR_INPUT
  req         : SYSHANDLE; // Request
  resp        : SYSHANDLE; // Response
  arg         : DINT;     // User argument
END_VAR;
VAR
  json  : SYSHANDLE;
  rc    : INT;
END_VAR;
  ...
  // Read body content from previous callback, if it is present
  rc := restRespBodyGetJSON(resp:=resp, json:=json);
 
  ...
 
  // Release json
  rc := jsonFree(o:=json);
  ...
 
END_FUNCTION;