HttpResponseToDataType - cHttpClient¶
Include: Use System\Http.pkg
Converts a JSON response body to the receiving DataFlex type.
Type: Function
Return data type: Variant converted to the receiving variable type
Parameters¶
| Parameter | Type | Description |
|---|---|---|
bOptRequireAll |
Boolean | Optional; defaults to True. Requires JSON object members needed by the destination type when True. |
sOptPath |
String | Optional dotted JSON path to select before conversion. |
Syntax¶
Function HttpResponseToDataType {Boolean bOptRequireAll} {String sOptPath} Returns Variant
Call¶
Get HttpResponseToDataType of hoObj False "json.username" to sUserName
Description¶
Response Content-Type must be JSON, either application/json or a compatible JSON content type. The receiving variable determines the DataFlex destination type: scalar JSON values can be read into scalar variables, JSON objects can be read into structs, and JSON arrays can be read into arrays.
Struct member mapping honors { Name="..." } metadata, so sUsername can map to username and asAttributes can map to attributes. bOptRequireAll=True requires JSON object members needed by the destination type; False allows partial data. sOptPath selects a nested JSON value before conversion; use dotted paths such as json and json.username.
Data type definitions¶
Struct HttpDT1
{ Name="username" }
String sUsername
{ Name="attributes" }
String[] asAttributes
End_Struct
Struct HttpBinResultDT1
{ Name="origin" }
String sOrigin
{ Name="url" }
String sUrl
{ Name="data" }
String sData
{ Name="json" }
HttpDT1 oJson
End_Struct
Examples¶
Whole response object¶
HttpBinResultDT1 oRet
Get HttpResponseToDataType of hoObj to oRet
Nested JSON object¶
HttpDT1 oRetUsr
Get HttpResponseToDataType of hoObj False "json" to oRetUsr
Nested scalar value¶
String sUserName
Get HttpResponseToDataType of hoObj False "json.username" to sUserName