jsonDecode()

JSON is a data exchange format and uses human-readable text for transmitting data objects. The data objects consist of attribute-value pairs and a sorted list of values. It is largely used instead of XML. Furthermore, it is used for asynchronous browser/server communication (AJAX).

The JSON text format is independent of programming languages and is therefore ideally suited for data exchange.

The function jsonDecode() decodes a string variable.

Synopsis

<any type> jsonDecode(string json);

Parameters

Parameter Meaning
json The string that is decoded. The variable was encoded by using the function jsonEncode().
Anmerkung: As of the version 3.18 the Byte-Order-Mark (BOM) is no longer processed but causes an error if it is contained in a string. See also the encoding parameters of the function fileToString().

Return Value

Decoded value

Description

The function jsonDecode() decodes a string variable that was encoded by using the function jsonEncode().

To detect decoding errors, use the function getLastError().

Note that since JSON only understands numeric and string data types, most of the WinCC OA data types are converted to strings.

There are, however some exceptions:

atime -> object with elements:time, count, dpid errClass -> object with elements: prio, type, id, text langString -> object with one element per language

A data type of time is always encoded in ISO-8601 format in UTC timezone, according to

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toJSON

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toISOString

Example

In the following example a dyn_int variable is encoded and then decoded.

main()
{
   anytype i, h;
   dyn_int k = makeDynInt(3,4,5,6);
   string j;
   j = jsonEncode(k);
   DebugN("Encode:", j);
   h = jsonDecode(j);
   DebugN("Decode:",h);
}       

Assignment

Misc. functions

Availability

UI

See also

jsonEncode()