JsonParse - method of the Pm object
Description:
Reads input text in the
JSON format and returns its binary representation in the form of objects (
PmMap), arrays (
PmArray) and values of elementary data types (
Integer,
String ...).
Syntax:
PmMap JsonParse(String sJson)
Parameters:
sJson | (String) Text string in the JSON format. |
---|
Return value:
The method returns
PmMap object containing information regarding the completed transformation.
Caution: This object does not represent the transmitted data - the data itself is contained in its
Value property.
The object has the following properties:
Value | Data read from input text.
The value can be represented by PmMap object, PmArray object or a value of elementary data type. |
ErrorCode | The numeric error code.
The 0 value means that the JSON string was read without error.
The 1 value means that an error occurred during reading. |
ErrorIndex | If an error occurred while reading the JSON string, then here will be the index of the character where the error occurred.
This property is not functional in Web panels |
Note:
Objects stored in
JSON will be represented by
PmMap objects, arrays stored in
JSON will be represented by
PmArray objects and other values stored in
JSON will be represented by values of corresponding data type (
Variant).
This hierarchical data in object form can be easily accessed in the PROMOTIC application either from
JavaScript, or from
VBScript.
This method is functional also in
Macro expression $.expr and in the
onDraw event of the
PmgCanvas object.
This method is also functional in
Web panels.
Example1:
Let there be a string in the
sJson variable:
[10, 20, 30, 40].
In
mMap.Value there will be an object of the
PmArray type.
Into the
vVal1 variable is saved the value of the item of the array on the index
1 (value 20).
JavaScriptVBScriptSelect and copy to clipboard
var mMap = Pm.JsonParse(sJson);
var oJson = mMap.Value;
var vVal1 = oJson.GetItem(1);
Dim mMap, oJson, vVal1
Set mMap = Pm.JsonParse(sJson)
Set oJson = mMap.Value
vVal1 = oJson.GetItem(1)
Example2:
Let there be a string in the
sJson variable:
{"position": {"x": 100, "y": 100}, "size": {"dx": 200, "dy": 100}}.
In
mMap.Value there will be an object of the
PmMap type.
Into the
vValX variable is saved the value of the
x property (value 100).
Into the
vValDx variable is saved the value of the
dy property (value 200).
JavaScriptVBScriptSelect and copy to clipboard
var mMap = Pm.JsonParse(sJson);
var oJson = mMap.Value;
var vValX = oJson.position.x;
var vValDx = oJson.size.dx;
Dim mMap, oJson, vValX, vValDx
Set mMap = Pm.JsonParse(sJson)
Set oJson = mMap.Value
vValX = oJson.position.x
vValDx = oJson.size.dx
Example3:
Let there be a string in the
sJson variable:
[{"x": 100, "y": 111}, {"x": 200, "y": 222}, {"x": 300, "y": 333}].
In
mMap.Value there will be an object of the
PmArray type.
Into the
vValX variable is saved the value of the
x property of the item on the index
1 (value 200).
Into the
vValY variable is saved the value of the
y property of the item on the index
1 (value 222).
JavaScriptVBScriptSelect and copy to clipboard
var mMap = Pm.JsonParse(sJson);
var oJson = mMap.Value;
var vValX = oJson.GetItem(1).x;
var vValY = oJson.GetItem(1).y;
Dim mMap, oJson, vValX, vValY
Set mMap = Pm.JsonParse(sJson)
Set oJson = mMap.Value
vValX = oJson.GetItem(1).x
vValY = oJson.GetItem(1).y
History:
Pm9.00.29:
ErrorCode and
ErrorIndex properties were added.
Pm9.00.28:
Fixed bug: The 2-dimensional array was not created correctly from the input text.
Pm9.00.09: Bugfix of
JSON parsing. The number is now always stored as
Double data type (previously as
Double data type or
Integer data type)