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 values:
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:
Value Data 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 oMap.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 oMap = Pm.JsonParse(sJson);
var oJson = oMap.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 oMap.Value there will be an object of the PmMap type.
Into the vValX variable is saved the value of the property x (value 100).
Into the vValDx variable is saved the value of the property dy (value 200).
JavaScriptVBScriptSelect and copy to clipboard

var oMap = Pm.JsonParse(sJson);
var oJson = oMap.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 oMap.Value there will be an object of the PmArray type.
Into the vValX variable is saved the value of the property x of the item on the index 1 (value 200).
Into the vValY variable is saved the value of the property y of the item on the index 1 (value 222).
JavaScriptVBScriptSelect and copy to clipboard

var oMap = Pm.JsonParse(sJson);
var oJson = oMap.Value;
var vValX = oJson.GetItem(1).x;
var vValY = oJson.GetItem(1).y;

History:
Pm9.00.09: Bugfix of JSON parsing. The number is now always stored as R8 (previously as R8 or I4)
Pm8.03.13: Created
PROMOTIC 9.0.17 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.Tavičská 845/21 703 00 Ostrava-Vítkovice