Promotic

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 a single property:
ValueData read from input text. The value can be represented by PmMap object, PmArray object or value of elementary data type.
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.
See also:
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 array item 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);
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;
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;

History:
Pm9.00.26: Now functional also for 2-dimensional array in the PmArray object.
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)
Pm8.03.13: Created
PROMOTIC 9.0.27 SCADA system documentation MICROSYS, spol. s r.o.

Send page remarkContact responsible person
Navigation:
 
- Pm
 
- Abs
- Cos
- E
- Exp
- JsonParse
 
 
- LN2
- PI
- Pow
- Sin
- Tan
© MICROSYS, spol. s r.o.